PageRenderTime 62ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Zikula/Framework/Controller/AbstractPlugin.php

https://github.com/antoniom/core
PHP | 120 lines | 72 code | 6 blank | 42 comment | 0 complexity | 48ad5260e638248ce8fbca95f1c8d964 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MIT
  1. <?php
  2. /**
  3. * Copyright Zikula Foundation 2009 - Zikula Application Framework
  4. *
  5. * This work is contributed to the Zikula Foundation under one or more
  6. * Contributor Agreements and licensed to You under the following license:
  7. *
  8. * @license GNU/LGPLv3 (or at your option, any later version).
  9. * @package Zikula
  10. *
  11. * Please see the NOTICE file distributed with this source code for further
  12. * information regarding copyright and licensing.
  13. */
  14. namespace Zikula\Framework\Controller;
  15. use Zikula\Framework\AbstractPlugin;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. /**
  18. * Zikula_Controller_AbstractPlugin class.
  19. */
  20. abstract class AbstractPlugin extends AbstractController
  21. {
  22. /**
  23. * Plugin name.
  24. *
  25. * @var string
  26. */
  27. protected $pluginName;
  28. /**
  29. * Parent module name.
  30. *
  31. * @var string
  32. */
  33. protected $moduleName;
  34. /**
  35. * Parent plugin instance.
  36. *
  37. * @var Zikula_AbstractPlugin
  38. */
  39. protected $plugin;
  40. /**
  41. * Constructor.
  42. *
  43. * @param ServiceManager $container ServiceManager.
  44. * @param AbstractPlugin $plugin Plugin.
  45. * @param array $options Options.
  46. */
  47. public function __construct(ServiceManager $container, AbstractPlugin $plugin, array $options = array())
  48. {
  49. $this->plugin = $plugin;
  50. parent::__construct($container, $options);
  51. }
  52. /**
  53. * Setup base properties.
  54. *
  55. * @return void
  56. */
  57. protected function _configureBase()
  58. {
  59. $this->getPath();
  60. $this->systemBaseDir = realpath('.');
  61. $class = get_class($this);
  62. $parts = strpos($class, '_') ? explode('_', $class) : explode('\\', $class);
  63. $this->name = $parts[0];
  64. $this->baseDir = $this->plugin->getBaseDir();
  65. $this->pluginName = $this->plugin->getPluginName();
  66. $this->moduleName = $this->plugin->getModuleName();
  67. $this->modinfo = $this->plugin->getModInfo();
  68. if (!$this->plugin->getPluginType() == AbstractPlugin::TYPE_SYSTEM) {
  69. $modbase = ($this->modinfo['type'] == AbstractPlugin::TYPE_MODULE) ? 'modules' : 'system';
  70. $this->baseDir = realpath("{$this->systemBaseDir}/$modbase/{$this->moduleName}/plugins/{$this->pluginName}");
  71. }
  72. $this->domain = $this->plugin->getDomain();
  73. }
  74. /**
  75. * Set view property.
  76. *
  77. * @param \Zikula_View $view Default null means new Render instance for this module name.
  78. *
  79. * @return AbstractPlugin
  80. */
  81. protected function setView(\Zikula_View $view = null)
  82. {
  83. // please note the docblock param signature is deliberately different to the method signature - drak
  84. if (is_null($view)) {
  85. if ($this->plugin->getPluginType() == AbstractPlugin::TYPE_MODULE) {
  86. $view = \Zikula_View_Plugin::getModulePluginInstance($this->moduleName, $this->pluginName);
  87. } else {
  88. $view = \Zikula_View_Plugin::getSystemPluginInstance($this->pluginName);
  89. }
  90. } else {
  91. if (!$view instanceof \Zikula_View_Plugin) {
  92. $name = is_object($view) ? get_class($view) : '$view';
  93. throw new \InvalidArgumentException(sprintf('%s must be an instance of Zikula_View_Plugin', $name));
  94. }
  95. }
  96. $this->view = $view;
  97. return $this;
  98. }
  99. /**
  100. * Set plugin for this controller.
  101. *
  102. * @param AbstractPlugin $plugin Plugin instance.
  103. *
  104. * @return void
  105. */
  106. public function setPlugin(AbstractPlugin $plugin)
  107. {
  108. $this->plugin = $plugin;
  109. }
  110. }