Example #1
0
 /**
  * @covers Xoops\Core\Handler\Scheme\LegacyModule::build
  */
 public function testBuild_optional()
 {
     $handler = Factory::getInstance()->newSpec()->scheme('legacy')->name('nosuchhandler')->dirname('avatars')->optional(true)->build();
     $this->assertNull($handler);
     $handler = Factory::getInstance()->newSpec()->scheme('legacy')->name('avatar')->dirname('avatars')->optional(true)->build();
     $this->assertInstanceOf('\\AvatarsAvatarHandler', $handler);
 }
Example #2
0
 /**
  * Get Module Handler
  *
  * @param string|null $name       name of handler
  * @param string|null $module_dir dirname of module
  * @param boolean     $optional   true if failure to load handler should be considered a warning, not an error
  *
  * @return XoopsObjectHandler|XoopsPersistableObjectHandler|bool
  */
 public function getModuleHandler($name = null, $module_dir = null, $optional = false)
 {
     // if $module_dir is not specified
     if (!isset($module_dir)) {
         // if a module is loaded
         if ($this->module instanceof XoopsModule) {
             $module_dir = $this->module->getVar('dirname', 'n');
         } else {
             trigger_error('No Module is loaded', E_USER_ERROR);
         }
     } else {
         $module_dir = trim($module_dir);
     }
     $name = !isset($name) ? $module_dir : trim($name);
     if (!isset($this->moduleHandlers[$module_dir][$name])) {
         if (!isset($this->handlerFactory)) {
             $this->handlerFactory = HandlerFactory::getInstance();
         }
         $handler = $this->handlerFactory->create($name, $module_dir, $optional);
         if ($handler === null) {
             $this->logger()->log(LogLevel::WARNING, sprintf('No handler for %s exists in module %s', $name, $module_dir));
         }
         $this->moduleHandlers[$module_dir][$name] = $handler;
     }
     return $this->moduleHandlers[$module_dir][$name];
 }
Example #3
0
 /**
  * @covers Xoops\Core\Handler\Scheme\Kernel::build
  */
 public function testBuild_optional()
 {
     $handler = Factory::getInstance()->newSpec()->scheme('kernel')->name('nosuchhandler')->optional(true)->build();
     $this->assertNull($handler);
     $handler = Factory::getInstance()->newSpec()->scheme('kernel')->name('user')->optional(true)->build();
     $this->assertInstanceOf('\\Xoops\\Core\\Kernel\\Handlers\\XoopsUserHandler', $handler);
 }
Example #4
0
/**
 * @deprecated
 * @param string $name
 * @param mixed $optional
 * @return XoopsObjectHandler|XoopsPersistableObjectHandler|null
 */
function xoops_getHandler($name, $optional = false)
{
    $xoops = Xoops::getInstance();
    $xoops->deprecated('xoops_getHandler(\'' . $name . '\') is deprecated. See how to replace it in file ' . __FILE__ . ' line ' . __LINE__);
    $handler = Factory::newSpec()->scheme('kernel')->name($name)->optional((bool) $optional)->build();
    return $handler;
}
Example #5
0
 /**
  * @covers Xoops\Core\Handler\Scheme\FQN::build
  */
 public function testBuild_optional()
 {
     $name = '\\Xoops\\Core\\Kernel\\Handlers\\NoSuchName';
     $spec = Factory::getInstance()->newSpec()->scheme('fqn')->name($name)->optional(true);
     $handler = $this->object->build($spec);
     $this->assertNull($handler);
     $name = '\\Xoops\\Core\\Kernel\\Handlers\\XoopsUserHandler';
     $spec = Factory::getInstance()->newSpec()->scheme('fqn')->name($name)->optional(true);
     $handler = $this->object->build($spec);
     $this->assertInstanceOf('\\Xoops\\Core\\Kernel\\Handlers\\XoopsUserHandler', $handler);
 }
 /**
  * @covers Xoops\Core\Handler\Scheme\SchemeInterface::build
  */
 public function testBuild()
 {
     $spec = Factory::getInstance()->newSpec();
     $this->assertNull($this->object->build($spec));
 }
Example #7
0
 /**
  * Initialize parent::__constuct calls this after verifying module object.
  *
  * @return void
  */
 public function init()
 {
     $this->mid = $this->module->getVar('mid');
     $this->dirname = $this->module->getVar('dirname');
     $this->permissionHandler = Factory::newSpec()->scheme('kernel')->name('groupperm')->build();
 }
Example #8
0
 /**
  * @return FactorySpec
  */
 public static function newSpec()
 {
     $instance = Factory::getInstance();
     $spec = FactorySpec::getInstance($instance);
     return $spec;
 }
Example #9
0
 /**
  * @covers Xoops\Core\Handler\Factory::db
  */
 public function testDb()
 {
     $this->assertInstanceOf('Xoops\\Core\\Database\\Connection', $this->object->db());
 }