BootstrapAbstract.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Application
  17. * @subpackage Bootstrap
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Application_Bootstrap_Bootstrapper
  24. */
  25. require_once 'Zend/Application/Bootstrap/Bootstrapper.php';
  26. /**
  27. * @see Zend_Application_Bootstrap_ResourceBootstrapper
  28. */
  29. require_once 'Zend/Application/Bootstrap/ResourceBootstrapper.php';
  30. /**
  31. * Abstract base class for bootstrap classes
  32. *
  33. * @uses Zend_Application_Bootstrap_Bootstrapper
  34. * @uses Zend_Application_Bootstrap_ResourceBootstrapper
  35. * @category Zend
  36. * @package Zend_Application
  37. * @subpackage Bootstrap
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. abstract class Zend_Application_Bootstrap_BootstrapAbstract
  42. implements Zend_Application_Bootstrap_Bootstrapper,
  43. Zend_Application_Bootstrap_ResourceBootstrapper
  44. {
  45. /**
  46. * @var Zend_Application|Zend_Application_Bootstrap_Bootstrapper
  47. */
  48. protected $_application;
  49. /**
  50. * @var array Internal resource methods (resource/method pairs)
  51. */
  52. protected $_classResources;
  53. /**
  54. * @var object Resource container
  55. */
  56. protected $_container;
  57. /**
  58. * @var string
  59. */
  60. protected $_environment;
  61. /**
  62. * Flattened (lowercase) option keys used for lookups
  63. *
  64. * @var array
  65. */
  66. protected $_optionKeys = array();
  67. /**
  68. * @var array
  69. */
  70. protected $_options = array();
  71. /**
  72. * @var Zend_Loader_PluginLoader_Interface
  73. */
  74. protected $_pluginLoader;
  75. /**
  76. * @var array Class-based resource plugins
  77. */
  78. protected $_pluginResources = array();
  79. /**
  80. * @var array Initializers that have been run
  81. */
  82. protected $_run = array();
  83. /**
  84. * @var array Initializers that have been started but not yet completed (circular dependency detection)
  85. */
  86. protected $_started = array();
  87. /**
  88. * Constructor
  89. *
  90. * Sets application object, initializes options, and prepares list of
  91. * initializer methods.
  92. *
  93. * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
  94. * @throws Zend_Application_Bootstrap_Exception When invalid application is provided
  95. */
  96. public function __construct($application)
  97. {
  98. $this->setApplication($application);
  99. $options = $application->getOptions();
  100. $this->setOptions($options);
  101. }
  102. /**
  103. * Set class state
  104. *
  105. * @param array $options
  106. * @return Zend_Application_Bootstrap_BootstrapAbstract
  107. */
  108. public function setOptions(array $options)
  109. {
  110. $this->_options = $this->mergeOptions($this->_options, $options);
  111. $options = array_change_key_case($options, CASE_LOWER);
  112. $this->_optionKeys = array_merge($this->_optionKeys, array_keys($options));
  113. $methods = get_class_methods($this);
  114. foreach ($methods as $key => $method) {
  115. $methods[$key] = strtolower($method);
  116. }
  117. if (array_key_exists('pluginpaths', $options)) {
  118. $pluginLoader = $this->getPluginLoader();
  119. foreach ($options['pluginpaths'] as $prefix => $path) {
  120. $pluginLoader->addPrefixPath($prefix, $path);
  121. }
  122. unset($options['pluginpaths']);
  123. }
  124. foreach ($options as $key => $value) {
  125. $method = 'set' . strtolower($key);
  126. if (in_array($method, $methods)) {
  127. $this->$method($value);
  128. } elseif ('resources' == $key) {
  129. foreach ($value as $resource => $resourceOptions) {
  130. $this->registerPluginResource($resource, $resourceOptions);
  131. }
  132. }
  133. }
  134. return $this;
  135. }
  136. /**
  137. * Get current options from bootstrap
  138. *
  139. * @return array
  140. */
  141. public function getOptions()
  142. {
  143. return $this->_options;
  144. }
  145. /**
  146. * Is an option present?
  147. *
  148. * @param string $key
  149. * @return bool
  150. */
  151. public function hasOption($key)
  152. {
  153. return in_array(strtolower($key), $this->_optionKeys);
  154. }
  155. /**
  156. * Retrieve a single option
  157. *
  158. * @param string $key
  159. * @return mixed
  160. */
  161. public function getOption($key)
  162. {
  163. if ($this->hasOption($key)) {
  164. $options = $this->getOptions();
  165. $options = array_change_key_case($options, CASE_LOWER);
  166. return $options[strtolower($key)];
  167. }
  168. return null;
  169. }
  170. /**
  171. * Merge options recursively
  172. *
  173. * @param array $array1
  174. * @param mixed $array2
  175. * @return array
  176. */
  177. public function mergeOptions(array $array1, $array2 = null)
  178. {
  179. if (is_array($array2)) {
  180. foreach ($array2 as $key => $val) {
  181. if (is_array($array2[$key])) {
  182. $array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
  183. ? $this->mergeOptions($array1[$key], $array2[$key])
  184. : $array2[$key];
  185. } else {
  186. $array1[$key] = $val;
  187. }
  188. }
  189. }
  190. return $array1;
  191. }
  192. /**
  193. * Get class resources (as resource/method pairs)
  194. *
  195. * Uses get_class_methods() by default, reflection on prior to 5.2.6,
  196. * as a bug prevents the usage of get_class_methods() there.
  197. *
  198. * @return array
  199. */
  200. public function getClassResources()
  201. {
  202. if (null === $this->_classResources) {
  203. if (version_compare(PHP_VERSION, '5.2.6') === -1) {
  204. $class = new ReflectionObject($this);
  205. $classMethods = $class->getMethods();
  206. $methodNames = array();
  207. foreach ($classMethods as $method) {
  208. $methodNames[] = $method->getName();
  209. }
  210. } else {
  211. $methodNames = get_class_methods($this);
  212. }
  213. $this->_classResources = array();
  214. foreach ($methodNames as $method) {
  215. if (5 < strlen($method) && '_init' === substr($method, 0, 5)) {
  216. $this->_classResources[strtolower(substr($method, 5))] = $method;
  217. }
  218. }
  219. }
  220. return $this->_classResources;
  221. }
  222. /**
  223. * Get class resource names
  224. *
  225. * @return array
  226. */
  227. public function getClassResourceNames()
  228. {
  229. $resources = $this->getClassResources();
  230. return array_keys($resources);
  231. }
  232. /**
  233. * Register a new resource plugin
  234. *
  235. * @param string|Zend_Application_Resource_Resource $resource
  236. * @param mixed $options
  237. * @return Zend_Application_Bootstrap_BootstrapAbstract
  238. * @throws Zend_Application_Bootstrap_Exception When invalid resource is provided
  239. */
  240. public function registerPluginResource($resource, $options = null)
  241. {
  242. if ($resource instanceof Zend_Application_Resource_Resource) {
  243. $resource->setBootstrap($this);
  244. $pluginName = $this->_resolvePluginResourceName($resource);
  245. $this->_pluginResources[$pluginName] = $resource;
  246. return $this;
  247. }
  248. if (!is_string($resource)) {
  249. throw new Zend_Application_Bootstrap_Exception('Invalid resource provided to ' . __METHOD__);
  250. }
  251. $this->_pluginResources[$resource] = $options;
  252. return $this;
  253. }
  254. /**
  255. * Unregister a resource from the bootstrap
  256. *
  257. * @param string|Zend_Application_Resource_Resource $resource
  258. * @return Zend_Application_Bootstrap_BootstrapAbstract
  259. * @throws Zend_Application_Bootstrap_Exception When unknown resource type is provided
  260. */
  261. public function unregisterPluginResource($resource)
  262. {
  263. if ($resource instanceof Zend_Application_Resource_Resource) {
  264. if ($index = array_search($resource, $this->_pluginResources, true)) {
  265. unset($this->_pluginResources[$index]);
  266. }
  267. return $this;
  268. }
  269. if (!is_string($resource)) {
  270. throw new Zend_Application_Bootstrap_Exception('Unknown resource type provided to ' . __METHOD__);
  271. }
  272. $resource = strtolower($resource);
  273. if (array_key_exists($resource, $this->_pluginResources)) {
  274. unset($this->_pluginResources[$resource]);
  275. }
  276. return $this;
  277. }
  278. /**
  279. * Is the requested plugin resource registered?
  280. *
  281. * @param string $resource
  282. * @return bool
  283. */
  284. public function hasPluginResource($resource)
  285. {
  286. return (null !== $this->getPluginResource($resource));
  287. }
  288. /**
  289. * Get a registered plugin resource
  290. *
  291. * @param string $resource
  292. * @return Zend_Application_Resource_Resource
  293. * @throws Zend_Application_Bootstrap_Exception
  294. */
  295. public function getPluginResource($resource)
  296. {
  297. if (array_key_exists(strtolower($resource), $this->_pluginResources)) {
  298. $resource = strtolower($resource);
  299. if (!$this->_pluginResources[$resource] instanceof Zend_Application_Resource_Resource) {
  300. $resourceName = $this->_loadPluginResource($resource, $this->_pluginResources[$resource]);
  301. if (!$resourceName) {
  302. throw new Zend_Application_Bootstrap_Exception(sprintf('Unable to resolve plugin "%s"; no corresponding plugin with that name', $resource));
  303. }
  304. $resource = $resourceName;
  305. }
  306. return $this->_pluginResources[$resource];
  307. }
  308. foreach ($this->_pluginResources as $plugin => $spec) {
  309. if ($spec instanceof Zend_Application_Resource_Resource) {
  310. $pluginName = $this->_resolvePluginResourceName($spec);
  311. if (0 === strcasecmp($resource, $pluginName)) {
  312. unset($this->_pluginResources[$plugin]);
  313. $this->_pluginResources[$pluginName] = $spec;
  314. return $spec;
  315. }
  316. continue;
  317. }
  318. if (false !== $pluginName = $this->_loadPluginResource($plugin, $spec)) {
  319. if (0 === strcasecmp($resource, $pluginName)) {
  320. return $this->_pluginResources[$pluginName];
  321. }
  322. continue;
  323. }
  324. if (class_exists($plugin)
  325. && is_subclass_of($plugin, 'Zend_Application_Resource_Resource')
  326. ) { //@SEE ZF-7550
  327. $spec = (array) $spec;
  328. $spec['bootstrap'] = $this;
  329. $instance = new $plugin($spec);
  330. $pluginName = $this->_resolvePluginResourceName($instance);
  331. unset($this->_pluginResources[$plugin]);
  332. $this->_pluginResources[$pluginName] = $instance;
  333. if (0 === strcasecmp($resource, $pluginName)) {
  334. return $instance;
  335. }
  336. }
  337. }
  338. return null;
  339. }
  340. /**
  341. * Retrieve all plugin resources
  342. *
  343. * @return array
  344. */
  345. public function getPluginResources()
  346. {
  347. foreach (array_keys($this->_pluginResources) as $resource) {
  348. $this->getPluginResource($resource);
  349. }
  350. return $this->_pluginResources;
  351. }
  352. /**
  353. * Retrieve plugin resource names
  354. *
  355. * @return array
  356. */
  357. public function getPluginResourceNames()
  358. {
  359. $this->getPluginResources();
  360. return array_keys($this->_pluginResources);
  361. }
  362. /**
  363. * Set plugin loader for loading resources
  364. *
  365. * @param Zend_Loader_PluginLoader_Interface $loader
  366. * @return Zend_Application_Bootstrap_BootstrapAbstract
  367. */
  368. public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader)
  369. {
  370. $this->_pluginLoader = $loader;
  371. return $this;
  372. }
  373. /**
  374. * Get the plugin loader for resources
  375. *
  376. * @return Zend_Loader_PluginLoader_Interface
  377. */
  378. public function getPluginLoader()
  379. {
  380. if ($this->_pluginLoader === null) {
  381. $options = array(
  382. 'Zend_Application_Resource' => 'Zend/Application/Resource',
  383. 'ZendX_Application_Resource' => 'ZendX/Application/Resource'
  384. );
  385. $this->_pluginLoader = new Zend_Loader_PluginLoader($options);
  386. }
  387. return $this->_pluginLoader;
  388. }
  389. /**
  390. * Set application/parent bootstrap
  391. *
  392. * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
  393. * @return Zend_Application_Bootstrap_BootstrapAbstract
  394. * @throws Zend_Application_Bootstrap_Exception
  395. */
  396. public function setApplication($application)
  397. {
  398. if (($application instanceof Zend_Application)
  399. || ($application instanceof Zend_Application_Bootstrap_Bootstrapper)
  400. ) {
  401. if ($application === $this) {
  402. throw new Zend_Application_Bootstrap_Exception('Cannot set application to same object; creates recursion');
  403. }
  404. $this->_application = $application;
  405. } else {
  406. throw new Zend_Application_Bootstrap_Exception('Invalid application provided to bootstrap constructor (received "' . get_class($application) . '" instance)');
  407. }
  408. return $this;
  409. }
  410. /**
  411. * Retrieve parent application instance
  412. *
  413. * @return Zend_Application|Zend_Application_Bootstrap_Bootstrapper
  414. */
  415. public function getApplication()
  416. {
  417. return $this->_application;
  418. }
  419. /**
  420. * Retrieve application environment
  421. *
  422. * @return string
  423. */
  424. public function getEnvironment()
  425. {
  426. if (null === $this->_environment) {
  427. $this->_environment = $this->getApplication()->getEnvironment();
  428. }
  429. return $this->_environment;
  430. }
  431. /**
  432. * Set resource container
  433. *
  434. * By default, if a resource callback has a non-null return value, this
  435. * value will be stored in a container using the resource name as the
  436. * key.
  437. *
  438. * Containers must be objects, and must allow setting public properties.
  439. *
  440. * @param object $container
  441. * @return Zend_Application_Bootstrap_BootstrapAbstract
  442. * @throws Zend_Application_Bootstrap_Exception
  443. */
  444. public function setContainer($container)
  445. {
  446. if (!is_object($container)) {
  447. throw new Zend_Application_Bootstrap_Exception('Resource containers must be objects');
  448. }
  449. $this->_container = $container;
  450. return $this;
  451. }
  452. /**
  453. * Retrieve resource container
  454. *
  455. * @return object
  456. */
  457. public function getContainer()
  458. {
  459. if (null === $this->_container) {
  460. $this->setContainer(new Zend_Registry());
  461. }
  462. return $this->_container;
  463. }
  464. /**
  465. * Determine if a resource has been stored in the container
  466. *
  467. * During bootstrap resource initialization, you may return a value. If
  468. * you do, it will be stored in the {@link setContainer() container}.
  469. * You can use this method to determine if a value was stored.
  470. *
  471. * @param string $name
  472. * @return bool
  473. */
  474. public function hasResource($name)
  475. {
  476. $resource = strtolower($name);
  477. $container = $this->getContainer();
  478. return isset($container->{$resource});
  479. }
  480. /**
  481. * Retrieve a resource from the container
  482. *
  483. * During bootstrap resource initialization, you may return a value. If
  484. * you do, it will be stored in the {@link setContainer() container}.
  485. * You can use this method to retrieve that value.
  486. *
  487. * If no value was returned, this will return a null value.
  488. *
  489. * @param string $name
  490. * @return null|mixed
  491. */
  492. public function getResource($name)
  493. {
  494. $resource = strtolower($name);
  495. $container = $this->getContainer();
  496. if ($this->hasResource($resource)) {
  497. return $container->{$resource};
  498. }
  499. return null;
  500. }
  501. /**
  502. * Implement PHP's magic to retrieve a resource
  503. * in the bootstrap
  504. *
  505. * @param string $prop
  506. * @return null|mixed
  507. */
  508. public function __get($prop)
  509. {
  510. return $this->getResource($prop);
  511. }
  512. /**
  513. * Implement PHP's magic to ask for the
  514. * existence of a resource in the bootstrap
  515. *
  516. * @param string $prop
  517. * @return bool
  518. */
  519. public function __isset($prop)
  520. {
  521. return $this->hasResource($prop);
  522. }
  523. /**
  524. * Bootstrap individual, all, or multiple resources
  525. *
  526. * Marked as final to prevent issues when subclassing and naming the
  527. * child class 'Bootstrap' (in which case, overriding this method
  528. * would result in it being treated as a constructor).
  529. *
  530. * If you need to override this functionality, override the
  531. * {@link _bootstrap()} method.
  532. *
  533. * @param null|string|array $resource
  534. * @return Zend_Application_Bootstrap_BootstrapAbstract
  535. * @throws Zend_Application_Bootstrap_Exception When invalid argument was passed
  536. */
  537. final public function bootstrap($resource = null)
  538. {
  539. $this->_bootstrap($resource);
  540. return $this;
  541. }
  542. /**
  543. * Overloading: intercept calls to bootstrap<resourcename>() methods
  544. *
  545. * @param string $method
  546. * @param array $args
  547. * @return Zend_Application_Bootstrap_BootstrapAbstract
  548. * @throws Zend_Application_Bootstrap_Exception On invalid method name
  549. */
  550. public function __call($method, $args)
  551. {
  552. if (9 < strlen($method) && 'bootstrap' === substr($method, 0, 9)) {
  553. $resource = substr($method, 9);
  554. return $this->bootstrap($resource);
  555. }
  556. throw new Zend_Application_Bootstrap_Exception('Invalid method "' . $method . '"');
  557. }
  558. /**
  559. * Bootstrap implementation
  560. *
  561. * This method may be overridden to provide custom bootstrapping logic.
  562. * It is the sole method called by {@link bootstrap()}.
  563. *
  564. * @param null|string|array $resource
  565. * @return void
  566. * @throws Zend_Application_Bootstrap_Exception When invalid argument was passed
  567. */
  568. protected function _bootstrap($resource = null)
  569. {
  570. if (null === $resource) {
  571. foreach ($this->getClassResourceNames() as $resource) {
  572. $this->_executeResource($resource);
  573. }
  574. foreach ($this->getPluginResourceNames() as $resource) {
  575. $this->_executeResource($resource);
  576. }
  577. } elseif (is_string($resource)) {
  578. $this->_executeResource($resource);
  579. } elseif (is_array($resource)) {
  580. foreach ($resource as $r) {
  581. $this->_executeResource($r);
  582. }
  583. } else {
  584. throw new Zend_Application_Bootstrap_Exception('Invalid argument passed to ' . __METHOD__);
  585. }
  586. }
  587. /**
  588. * Execute a resource
  589. *
  590. * Checks to see if the resource has already been run. If not, it searches
  591. * first to see if a local method matches the resource, and executes that.
  592. * If not, it checks to see if a plugin resource matches, and executes that
  593. * if found.
  594. *
  595. * Finally, if not found, it throws an exception.
  596. *
  597. * @param string $resource
  598. * @return void
  599. * @throws Zend_Application_Bootstrap_Exception When resource not found
  600. */
  601. protected function _executeResource($resource)
  602. {
  603. $resourceName = strtolower($resource);
  604. if (in_array($resourceName, $this->_run)) {
  605. return;
  606. }
  607. if (isset($this->_started[$resourceName]) && $this->_started[$resourceName]) {
  608. throw new Zend_Application_Bootstrap_Exception('Circular resource dependency detected');
  609. }
  610. $classResources = $this->getClassResources();
  611. if (array_key_exists($resourceName, $classResources)) {
  612. $this->_started[$resourceName] = true;
  613. $method = $classResources[$resourceName];
  614. $return = $this->$method();
  615. unset($this->_started[$resourceName]);
  616. $this->_markRun($resourceName);
  617. if (null !== $return) {
  618. $this->getContainer()->{$resourceName} = $return;
  619. }
  620. return;
  621. }
  622. if ($this->hasPluginResource($resource)) {
  623. $this->_started[$resourceName] = true;
  624. $plugin = $this->getPluginResource($resource);
  625. $return = $plugin->init();
  626. unset($this->_started[$resourceName]);
  627. $this->_markRun($resourceName);
  628. if (null !== $return) {
  629. $this->getContainer()->{$resourceName} = $return;
  630. }
  631. return;
  632. }
  633. throw new Zend_Application_Bootstrap_Exception('Resource matching "' . $resource . '" not found');
  634. }
  635. /**
  636. * Load a plugin resource
  637. *
  638. * @param string $resource
  639. * @param array|object|null $options
  640. * @return string|false
  641. */
  642. protected function _loadPluginResource($resource, $options)
  643. {
  644. $options = (array) $options;
  645. $options['bootstrap'] = $this;
  646. $className = $this->getPluginLoader()->load(strtolower($resource), false);
  647. if (!$className) {
  648. return false;
  649. }
  650. $instance = new $className($options);
  651. unset($this->_pluginResources[$resource]);
  652. if (isset($instance->_explicitType)) {
  653. $resource = $instance->_explicitType;
  654. }
  655. $resource = strtolower($resource);
  656. $this->_pluginResources[$resource] = $instance;
  657. return $resource;
  658. }
  659. /**
  660. * Mark a resource as having run
  661. *
  662. * @param string $resource
  663. * @return void
  664. */
  665. protected function _markRun($resource)
  666. {
  667. if (!in_array($resource, $this->_run)) {
  668. $this->_run[] = $resource;
  669. }
  670. }
  671. /**
  672. * Resolve a plugin resource name
  673. *
  674. * Uses, in order of preference
  675. * - $_explicitType property of resource
  676. * - Short name of resource (if a matching prefix path is found)
  677. * - class name (if none of the above are true)
  678. *
  679. * The name is then cast to lowercase.
  680. *
  681. * @param Zend_Application_Resource_Resource $resource
  682. * @return string
  683. */
  684. protected function _resolvePluginResourceName($resource)
  685. {
  686. if (isset($resource->_explicitType)) {
  687. $pluginName = $resource->_explicitType;
  688. } else {
  689. $className = get_class($resource);
  690. $pluginName = $className;
  691. $loader = $this->getPluginLoader();
  692. foreach ($loader->getPaths() as $prefix => $paths) {
  693. if (0 === strpos($className, $prefix)) {
  694. $pluginName = substr($className, strlen($prefix));
  695. $pluginName = trim($pluginName, '_');
  696. break;
  697. }
  698. }
  699. }
  700. $pluginName = strtolower($pluginName);
  701. return $pluginName;
  702. }
  703. }