Example #1
1
 /**
  * Create and return a StorageInterface instance
  *
  * @param  string                             $type
  * @param  array|Traversable                  $options
  * @return StorageInterface
  * @throws Exception\InvalidArgumentException for unrecognized $type or individual options
  */
 public static function factory($type, $options = array())
 {
     if (!is_string($type)) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects the $type argument to be a string class name; received "%s"', __METHOD__, is_object($type) ? get_class($type) : gettype($type)));
     }
     if (!class_exists($type)) {
         $class = __NAMESPACE__ . '\\' . $type;
         if (!class_exists($class)) {
             throw new Exception\InvalidArgumentException(sprintf('%s expects the $type argument to be a valid class name; received "%s"', __METHOD__, $type));
         }
         $type = $class;
     }
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (!is_array($options)) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects the $options argument to be an array or Traversable; received "%s"', __METHOD__, is_object($options) ? get_class($options) : gettype($options)));
     }
     switch (true) {
         case in_array('Zend\\Session\\Storage\\AbstractSessionArrayStorage', class_parents($type)):
             return static::createSessionArrayStorage($type, $options);
             break;
         case $type === 'Zend\\Session\\Storage\\ArrayStorage':
         case in_array('Zend\\Session\\Storage\\ArrayStorage', class_parents($type)):
             return static::createArrayStorage($type, $options);
             break;
         case in_array('Zend\\Session\\Storage\\StorageInterface', class_implements($type)):
             return new $type($options);
             break;
         default:
             throw new Exception\InvalidArgumentException(sprintf('Unrecognized type "%s" provided; expects a class implementing %s\\StorageInterface', $type, __NAMESPACE__));
     }
 }
Example #2
0
 private function validatePackage($packageName)
 {
     if (class_exists($packageName) && in_array('Tohmua\\IntegrationGate\\IntegrationGate', class_implements($packageName))) {
         return true;
     }
     return false;
 }
Example #3
0
 public function testGenerator()
 {
     /** @var OpsWay\Test2\Solid\I $generator */
     $generator = OpsWay\Test2\Solid\Factory::create('i');
     $generator->generate();
     $this->assertFileExists($file = __DIR__ . '/../../test/I/IGeometric.php');
     include $file;
     $this->assertTrue(interface_exists('IGeometric'));
     $this->assertFileExists($file = __DIR__ . '/../../test/I/IAngular.php');
     include $file;
     $this->assertTrue(interface_exists('IAngular'));
     $this->assertFileExists($file = __DIR__ . '/../../test/I/ISquarable.php');
     include $file;
     $this->assertTrue(interface_exists('ISquarable'));
     $this->assertFileExists($file = __DIR__ . '/../../test/I/Square.php');
     include $file;
     $this->assertTrue(class_exists('Square'));
     $this->assertTrue(in_array('IGeometric', class_implements('Square')));
     $this->assertFileExists($file = __DIR__ . '/../../test/I/Circle.php');
     include $file;
     $this->assertTrue(class_exists('Circle'));
     $this->assertTrue(in_array('IGeometric', class_implements('Circle')));
     $this->assertTrue(method_exists('IGeometric', 'square'));
     $this->assertTrue(method_exists('ISquarable', 'square'));
     $this->assertTrue(method_exists('IAngular', 'countAngles'));
 }
 /**
  * Class mutator
  *
  * @param string $class Class name
  *
  * @return void
  * @throws \InvalidArgumentException If wrong class is given
  */
 private function _setClass($class)
 {
     if (!in_array(IBasket::class, class_implements($class))) {
         throw new \InvalidArgumentException('Class must implement IBasket');
     }
     $this->_class = $class;
 }
 public function canCreate(ContainerInterface $container, $requestedName)
 {
     $isClassExists = class_exists($requestedName);
     $isDispatchable = in_array(DispatchableInterface::class, class_implements($requestedName));
     $isController = preg_match('/^[a-z]+\\\\Controller\\\\.*Controller/i', $requestedName);
     return $isClassExists && $isDispatchable && $isController;
 }
Example #6
0
 public static function is_multiselectable($object)
 {
     if (is_object($object)) {
         if ($object instanceof VP_MultiSelectable) {
             return true;
         }
     } elseif (is_string($object)) {
         $class = self::field_class_from_type($object);
         if (function_exists('class_implements')) {
             if (class_exists($class)) {
                 $interfaces = class_implements($class);
                 if (isset($interfaces['VP_MultiSelectable'])) {
                     return true;
                 }
             } else {
                 return false;
             }
         } else {
             $dummy = new $class();
             if ($dummy instanceof VP_MultiSelectable) {
                 return true;
             }
             unset($dummy);
         }
     }
     return false;
 }
Example #7
0
    /**
     * Dumps a set of routes to a PHP class.
     *
     * Available options:
     *
     *  * class:      The class name
     *  * base_class: The base class name
     *
     * @param array $options An array of options
     *
     * @return string A PHP class representing the matcher class
     */
    public function dump(array $options = array())
    {
        $options = array_replace(array('class' => 'ProjectUrlMatcher', 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher'), $options);
        // trailing slash support is only enabled if we know how to redirect the user
        $interfaces = class_implements($options['base_class']);
        $supportsRedirections = isset($interfaces['Symfony\\Component\\Routing\\Matcher\\RedirectableUrlMatcherInterface']);
        return <<<EOF
<?php

use Symfony\\Component\\Routing\\Exception\\MethodNotAllowedException;
use Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException;
use Symfony\\Component\\Routing\\RequestContext;

/**
 * {$options['class']}
 *
 * This class has been auto-generated
 * by the Symfony Routing Component.
 */
class {$options['class']} extends {$options['base_class']}
{
    /**
     * Constructor.
     */
    public function __construct(RequestContext \$context)
    {
        \$this->context = \$context;
    }

{$this->generateMatchMethod($supportsRedirections)}
}

EOF;
    }
 /**
  * Returns a list of interfaces implemented by instance
  * @param $instance
  * @return array
  */
 protected function getDependencyInterfaces($instance) : array
 {
     $interfaces = class_implements($instance);
     array_push($interfaces, get_class($instance));
     $interfaces += class_parents($instance);
     return $interfaces;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function getType($name)
 {
     if (!is_string($name)) {
         throw new UnexpectedTypeException($name, 'string');
     }
     if (!isset($this->types[$name])) {
         $type = null;
         foreach ($this->extensions as $extension) {
             if ($extension->hasType($name)) {
                 $type = $extension->getType($name);
                 break;
             }
         }
         if (!$type) {
             // Support fully-qualified class names
             if (class_exists($name) && in_array('Symfony\\Component\\Form\\FormTypeInterface', class_implements($name))) {
                 $type = new $name();
             } else {
                 throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name));
             }
         }
         $this->resolveAndAddType($type);
     }
     if (isset($this->legacyNames[$name])) {
         @trigger_error('Accessing types by their string name is deprecated since version 2.8 and will be removed in 3.0. Use the fully-qualified type class name instead.', E_USER_DEPRECATED);
     }
     return $this->types[$name];
 }
Example #10
0
 /**
  * Loads the composite driver from constants
  * @param $level
  * @return \Stash\Interfaces\DriverInterface
  */
 protected function loadConfig($level)
 {
     $drivers = array();
     $driver_configs = Config::get("concrete.cache.levels.{$level}.drivers", array());
     foreach ($driver_configs as $driver_build) {
         if (!$driver_build) {
             continue;
         }
         $class = array_get($driver_build, 'class', '');
         if ($class && class_exists($class)) {
             $implements = class_implements($class);
             // Make sure that the provided class implements the DriverInterface
             if (isset($implements['Stash\\Interfaces\\DriverInterface'])) {
                 /** @type \Stash\Interfaces\DriverInterface $temp_driver */
                 $temp_driver = new $class();
                 if ($options = array_get($driver_build, 'options', null)) {
                     $temp_driver->setOptions($options);
                 }
                 $drivers[] = $temp_driver;
             } else {
                 throw new \RuntimeException('Cache driver class must implement \\Stash\\Interfaces\\DriverInterface.');
             }
         }
     }
     $count = count($drivers);
     if ($count > 1) {
         $driver = new Composite();
         $driver->setOptions(array('drivers' => $drivers));
     } elseif ($count === 1) {
         $driver = $drivers[0];
     } else {
         $driver = new BlackHole();
     }
     return $driver;
 }
Example #11
0
 protected function afterSaving($request)
 {
     if (!in_array('LiveCMS\\Models\\Contracts\\UserOnlyInterface', class_implements($this->model))) {
         if ($request->has('permalink')) {
             $permalink = $this->model->permalink;
             if ($permalink == null) {
                 $permalink = new Permalink();
                 $permalink->postable()->associate($this->model);
             }
             $permalink->permalink = $request->get('permalink');
             $permalink->save();
         } else {
             if ($this->model->permalink) {
                 $this->model->permalink->delete();
             }
         }
     }
     if ($request->hasFile('picture') && $request->file('picture')->isValid()) {
         $object = $this->model;
         Upload::setFilenameMaker(function ($file, $object) {
             $title = $object->title ? $object->title : $object->name;
             return str_limit(str_slug($title . ' ' . date('YmdHis')), 200) . '.' . $file->getClientOriginalExtension();
         }, $object);
         Upload::model($object);
         $this->model->save();
     }
     if (empty($this->model->status)) {
         $status = Model::STATUS_DRAFT;
         $this->model->update(compact('status'));
     }
     return parent::afterSaving($request);
 }
Example #12
0
 /**
  * Get a new function core instance
  *
  * @param array $cfg Function core configuration for initialization
  * @param array $common Common configuration for initialization
  * @param \Facula\Framework $parent Instance of Facula Framework itself.
  *
  * @return mixed Return a instance of function core when success, false otherwise
  */
 public static final function getInstance(array $cfg, array $common, Framework $parent)
 {
     $caller = get_called_class();
     // If $cfg['Core'] has beed set, means user wants
     // to use their own core instead of default one
     if (isset($cfg['Custom'][0])) {
         $class = $cfg['Custom'];
     } elseif (isset(static::$default)) {
         $class = static::$default;
     } else {
         new Error('CLASS_NOTFOUND', array($caller), 'ERROR');
         return false;
     }
     if (!isset(self::$instances[$class])) {
         if (!class_exists($class)) {
             new Error('CLASS_NOTLOAD', array($class), 'ERROR');
             return false;
         }
         $classInterface = class_implements($class);
         if (!isset($classInterface[static::$interface])) {
             new Error('CLASS_INTERFACE', array($class, static::$interface), 'ERROR');
             return false;
         }
         if (!is_subclass_of($class, 'Facula\\Base\\Prototype\\Core')) {
             new Error('CLASS_BASE', array($class, 'Facula\\Base\\Prototype\\Core'), 'ERROR');
             return false;
         }
         return self::$instances[$class] = new $class($cfg, $common, $parent);
     }
     return self::$instances[$class];
 }
 /**
  * Serialize data
  *
  * @param mixed $data the data to serialize
  *
  * @return string serialized form of $data
  */
 public static function sanitizeForSerialization($data)
 {
     if (is_scalar($data) || null === $data) {
         return $data;
     } elseif ($data instanceof \DateTime) {
         return $data->format(\DateTime::ATOM);
     } elseif (is_array($data)) {
         foreach ($data as $property => $value) {
             $data[$property] = self::sanitizeForSerialization($value);
         }
         return $data;
     } elseif (is_object($data)) {
         if (!isset(class_implements($data)["ArrayAccess"])) {
             return $data;
         }
         $values = array();
         foreach (array_keys($data::swaggerTypes()) as $property) {
             $getter = $data::getters()[$property];
             if ($data->{$getter}() !== null) {
                 $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($data->{$getter}());
             }
         }
         return (object) $values;
     } else {
         return (string) $data;
     }
 }
 static function class_implements($c, $autoload = true)
 {
     if (is_object($c)) {
         $class = get_class($c);
     } else {
         if (!class_exists($c, $autoload) && !interface_exists($c, false) && !trait_exists($c, false)) {
             user_error(__FUNCTION__ . '(): Class ' . $c . ' does not exist and could not be loaded', E_USER_WARNING);
             return false;
         } else {
             $c = self::ns2us($c);
         }
     }
     /**/
     if (function_exists('class_implements')) {
         $autoload = class_implements($c, false);
         /**/
     } else {
         if (class_exists('ReflectionClass', false)) {
             $autoload = array();
             $c = new ReflectionClass($c);
             foreach ($c->getInterfaceNames() as $c) {
                 $autoload[$c] = $c;
             }
             /**/
         } else {
             return false;
             /**/
         }
     }
     foreach ($autoload as $c) {
         isset(self::$us2ns[$a = strtolower($c)]) && ($autoload[$c] = self::$us2ns[$a]);
     }
     return $autoload;
 }
Example #15
0
 /**
  * @param ApiCallData $data
  *
  * @return ApiResponseInterface
  *
  * @throws \Exception
  */
 public static function create(ApiCallData $data)
 {
     $type = $data->getResponseType();
     if (!class_exists($type)) {
         throw new \Exception("Type Class '" . $type . "', could not be loaded");
     }
     $interfaces = class_implements($type);
     if ($type == '\\Exception' || $type === '\\Packaged\\Api\\Exceptions\\ApiException' || in_array('\\Packaged\\Api\\Exceptions\\ApiException', $interfaces) || array_key_exists('Exception', class_parents($type))) {
         $code = $data->getStatusCode();
         if (!is_numeric($code)) {
             $code = 500;
         }
         $exception = new $type($data->getStatusMessage(), $code);
         $rawData = $data->getRawResult();
         if (is_object($rawData)) {
             Objects::hydrate($exception, $rawData);
         }
         throw $exception;
     } else {
         if (in_array('Packaged\\Api\\Interfaces\\ApiResponseInterface', $interfaces)) {
             $class = new $type();
             /**
              * @var $class \Packaged\Api\Interfaces\ApiResponseInterface
              */
             $class->setApiCallData($data);
             return $class;
         } else {
             throw new ApiException("An invalid message type was used '" . $type . "'");
         }
     }
 }
Example #16
0
 public function findRepositoryName($className)
 {
     //Check repository name using convention of "Repository" suffix
     //in the same namespace.
     //C.o.C is awesome, you should use it !!
     $repoName = "{$className}Repository";
     if (class_exists($repoName) && in_array("Spot\\Domain\\Repository", class_implements($repoName)) && $repoName::repositoryOf() == $className) {
         return $repoName;
     }
     $repos = $this->reflection->find(substr($className, 0, strpos($className, "\\")), Match::instantiableOnly()->andIt(Match::subTypeOf("Spot\\Domain\\Repository")));
     foreach ($repos as $repo) {
         $repoName = $repo->name;
         if ($repoName::repositoryOf() == $className) {
             return $repoName;
         }
     }
     // search class inheritance hierarchies
     $candidates = [];
     $classParents = array_values(class_parents($className) ?: []);
     foreach ($repos as $repo) {
         $repoName = $repo->name;
         $index = array_search($repoName::repositoryOf(), $classParents);
         if ($index !== false) {
             $candidates[$index] = $repoName;
         }
     }
     if (!empty($candidates)) {
         // check closest candidates
         return $candidates[min(array_keys($candidates))];
     }
     throw new \RuntimeException("Repository of {$className} can't be found");
 }
 /**
  * @param $argument
  * @return array
  */
 private function getAllInterfaces($argument)
 {
     $interfaces = array_filter(class_implements($argument), function ($el) {
         return 0 !== strpos($el, 'Prophecy\\');
     });
     return $interfaces;
 }
Example #18
0
 private static function _dumpWithReflection($var, $maxDepth)
 {
     $return = null;
     $isObj = is_object($var);
     if ($isObj && in_array('Doctrine\\Common\\Collections\\Collection', class_implements($var))) {
         $var = $var->toArray();
     }
     if ($maxDepth) {
         if (is_array($var)) {
             $return = array();
             foreach ($var as $k => $v) {
                 $return[$k] = self::_dumpWithReflection($v, $maxDepth - 1);
             }
         } else {
             if ($isObj) {
                 $reflClass = new \ReflectionClass(get_class($var));
                 $return = new \stdclass();
                 $return->{'__CLASS__'} = get_class($var);
                 foreach ($reflClass->getProperties() as $reflProperty) {
                     $reflProperty->setAccessible(true);
                     $name = $reflProperty->getName();
                     $value = $reflProperty->getValue($var);
                     $return->{$name} = self::_dumpWithReflection($value, $maxDepth - 1);
                 }
             } else {
                 $return = $var;
             }
         }
     } else {
         $return = is_object($var) ? get_class($var) : (is_array($var) ? 'Array(' . count($var) . ')' : $var);
     }
     return $return;
 }
Example #19
0
 /**
  * @return array
  */
 public function getTypesWithin()
 {
     if ($this->typesWithing !== NULL) {
         return $this->typesWithing;
     }
     return $this->typesWithing = class_parents($class = $this->originalType->getName()) + class_implements($class) + [$class => $class];
 }
Example #20
0
 /**
  * Kaltura client constructor
  *
  * @param KalturaConfiguration $config
  */
 public function __construct(KalturaConfiguration $config)
 {
     $this->config = $config;
     $logger = $this->config->getLogger();
     if ($logger) {
         $this->shouldLog = true;
     }
     // load all plugins
     $pluginsFolder = realpath(dirname(__FILE__)) . '/KalturaPlugins';
     if (is_dir($pluginsFolder)) {
         $dir = dir($pluginsFolder);
         while (false !== ($fileName = $dir->read())) {
             $matches = null;
             if (preg_match('/^([^.]+).php$/', $fileName, $matches)) {
                 require_once "{$pluginsFolder}/{$fileName}";
                 $pluginClass = $matches[1];
                 if (!class_exists($pluginClass) || !in_array('IKalturaClientPlugin', class_implements($pluginClass))) {
                     continue;
                 }
                 $plugin = call_user_func(array($pluginClass, 'get'), $this);
                 if (!$plugin instanceof IKalturaClientPlugin) {
                     continue;
                 }
                 $pluginName = $plugin->getName();
                 $services = $plugin->getServices();
                 foreach ($services as $serviceName => $service) {
                     $service->setClient($this);
                     $this->pluginServices[$serviceName] = $service;
                 }
             }
         }
     }
 }
Example #21
0
 /**
  * Creates a new button of the given type
  *
  * @param string $button ButtonClass to invoke. Must implement ButtonInterface
  *
  * @throws \InvalidArgumentException In case a ButtonClass does not implement
  * ButtonInterface
  *
  * @return ButtonInterface
  */
 public function makeButton($button)
 {
     if (!in_array(ButtonInterface::class, class_implements($button), true)) {
         throw new \InvalidArgumentException('A Button must implement ButtonInterface', 1441706378);
     }
     return GeneralUtility::makeInstance($button);
 }
Example #22
0
 private function callStaticInfoMethod($classnames, $methodName)
 {
     $knownItems = [];
     foreach ($classnames as $classname) {
         $implementedInterfaces = class_implements($classname);
         if ($implementedInterfaces === false) {
             throw new JigException("Failed to load plugin class {$classname} to get info from it.");
         }
         if (in_array('Jig\\Plugin', $implementedInterfaces) == false) {
             $message = "Class {$classname} does not implement interface Jig\\Plugin, cannot be used as a plugin.";
             throw new JigException($message);
         }
         $callable = [$classname, $methodName];
         $listItems = call_user_func($callable);
         if (is_array($listItems) == false) {
             $message = sprintf("Method %s for class %s must return an array of the names, and the names must be strings", $methodName, $classname);
             throw new JigException($message, JigException::FILTER_NO_INFO);
         }
         foreach ($listItems as $item) {
             if (is_string($item) == false) {
                 $message = sprintf("Method %s for class %s must return an array of the names, and the names must be strings", $methodName, $classname);
                 throw new JigException($message, JigException::FILTER_NO_INFO);
             }
         }
         //TODO - should we detect and warn on duplicate filters here?
         $knownItems = array_merge($knownItems, $listItems);
     }
     return $knownItems;
 }
 /**
  * @param DataObject $record
  * @throws InvalidArgumentException if record doesn't implement CMSPreviewable
  */
 public function __construct($record)
 {
     if (!in_array('CMSPreviewable', class_implements($record))) {
         throw new InvalidArgumentException(sprintf('SilverStripeNavigator: Record of type %s doesn\'t implement CMSPreviewable', get_class($record)));
     }
     $this->record = $record;
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function register(GloubsterServerInterface $server)
 {
     foreach ($server['configuration']['listeners'] as $listenerConf) {
         $class_name = $listenerConf['type'];
         if (!class_exists($class_name)) {
             $server['monolog']->addError(sprintf('%s is not a valid classname', $class_name));
             continue;
         }
         if (!in_array('Gloubster\\Server\\Listener\\JobListenerInterface', class_implements($class_name))) {
             $server['monolog']->addError(sprintf('%s is not implementing JobListenerInterface', $class_name));
             continue;
         }
         try {
             $listener = $class_name::create($server, $listenerConf['options']);
         } catch (RuntimeException $e) {
             $server['monolog']->addError(sprintf('Error while creating listener %s : %s', $listenerConf['type'], $e->getMessage()));
             continue;
         }
         $server['monolog']->addInfo(sprintf('Attaching listener %s', get_class($listener)));
         $listener->attach($server['message-handler']);
         $this->listeners[] = $listener;
     }
     $component = $this;
     $server['dispatcher']->on('booted', function (GloubsterServerInterface $server) use($component) {
         foreach ($component->listeners as $listener) {
             $listener->listen();
         }
     });
     $server['dispatcher']->on('stop', function ($server) use($component) {
         foreach ($component->listeners as $listener) {
             $listener->shutdown();
         }
     });
 }
 /**
  * {@inheritdoc}
  */
 public function guessPatternType($contextClass)
 {
     if (!in_array('Behat\\Behat\\Context\\CustomSnippetAcceptingContext', class_implements($contextClass))) {
         return null;
     }
     return $contextClass::getAcceptedSnippetType();
 }
 /**
  * Return the title, description, keywords and language metatags.
  * 
  * @todo Move <title> tag in separate getter for easier customization and more obvious usage
  * 
  * @param boolean|string $includeTitle Show default <title>-tag, set to false for custom templating
  * @return string The XHTML metatags
  */
 public function MetaTags($includeTitle = true)
 {
     $tags = "";
     if ($includeTitle === true || $includeTitle == 'true') {
         $tags .= "<title>" . Convert::raw2xml($this->Title) . "</title>\n";
     }
     $generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));
     if (!empty($generator)) {
         $tags .= "<meta name=\"generator\" content=\"" . Convert::raw2att($generator) . "\" />\n";
     }
     $charset = Config::inst()->get('ContentNegotiator', 'encoding');
     $tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset={$charset}\" />\n";
     if ($this->MetaDescription) {
         $tags .= "<meta name=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n";
     }
     if ($this->ExtraMeta) {
         $tags .= $this->ExtraMeta . "\n";
     }
     if (Permission::check('CMS_ACCESS_CMSMain') && in_array('CMSPreviewable', class_implements($this)) && !$this instanceof ErrorPage) {
         $tags .= "<meta name=\"x-page-id\" content=\"{$this->ID}\" />\n";
         $tags .= "<meta name=\"x-cms-edit-link\" content=\"" . $this->CMSEditLink() . "\" />\n";
     }
     $this->extend('MetaTags', $tags);
     return $tags;
 }
Example #27
0
 /**
  * Gets the correct class for the given library and module. More documentation to come...
  */
 private static function _construct($entity_or_library, $module, $filename = false, $meta_info = false)
 {
     $library = self::_get_library($entity_or_library);
     if (!$filename) {
         $filename = 'classes/media/' . $library . '/' . $module . '.php';
     }
     if (reason_file_exists($filename)) {
         reason_include_once($filename);
         $classname = self::_convert_to_camel_case($module);
         if ($meta_info) {
             $library_classname = ucfirst($library) . $meta_info . $classname;
         } else {
             $library_classname = ucfirst($library) . $classname;
         }
         if (class_exists($library_classname)) {
             $interface_file = 'classes/media/interfaces/' . $module . '_interface.php';
             if (reason_file_exists($interface_file)) {
                 reason_include_once($interface_file);
                 $class = new $library_classname();
                 $implemented = class_implements($class);
                 if (isset($implemented[$classname . 'Interface'])) {
                     return $class;
                 } else {
                     trigger_error($library_classname . ' must implement ' . $classname . 'Interface.');
                 }
             } else {
                 trigger_error($module . ' interface file does not exist: ' . $interface_file);
             }
         } else {
             trigger_error($module . ' class does not exist: ' . $library_classname);
         }
     } else {
         trigger_error($module . ' file does not exist: ' . $filename);
     }
 }
Example #28
0
 /**
  * Asserts that item type is collection defined type
  *
  * @param string $instanceName
  * @param string|int|null $index
  * @return void
  * @throws \InvalidArgumentException
  */
 private function assertValidTypeLazy($instanceName, $index = null)
 {
     $realType = $this->configInterface->getInstanceType($this->configInterface->getPreference($instanceName));
     if (!in_array($this->type, array_unique(array_merge(class_parents($realType), class_implements($realType))), true)) {
         $this->throwTypeException($realType, $index);
     }
 }
Example #29
0
 protected function dumpObject($obj, $hash)
 {
     if (isset($this->objectsDepth[$hash])) {
         if ($this->objectsDepth[$hash] < $this->depth) {
             $this->refPool[$this->counter]['ref_counter'] = $this->counter;
             $this->dumpRef(true, $this->counter, $obj, 'object');
             return;
         } else {
             unset($this->objectsDepth[$hash]);
         }
     }
     $a = (array) $obj;
     $c = get_class($obj);
     $p = array($c => $c) + class_parents($obj) + class_implements($obj) + array('*' => '*');
     foreach (array_reverse($p) as $p) {
         if (!empty($this->casters[$p = 'o:' . strtolower($p)])) {
             foreach ($this->casters[$p] as $p) {
                 try {
                     $a = call_user_func($p, $obj, $a);
                 } catch (\Exception $e) {
                 }
             }
         }
     }
     $this->walkHash($c, $a, count($a));
 }
Example #30
0
 /**
  * Dynamically loads a plugin by name.
  *
  * @param string $className Fully qualified plugin class name
  * @param array  $options   Options
  *
  * @throws \Exception
  */
 public function load($className, $options)
 {
     if (!class_exists($className)) {
         throw new \Exception('The plugin class "' . $className . '" could not be found.');
     }
     // make sure the class implements the plugin interface
     if (!in_array(PluginInterface::class, class_implements($className))) {
         throw new \Exception('The class "' . $className . '" is not a plugin.');
     }
     try {
         /** @var PluginInterface $instance */
         $instance = new $className($this->bot, $this);
         foreach ($options as $key => $value) {
             if (property_exists($instance, $key)) {
                 $instance->{$key} = $value;
             } else {
                 throw new \Exception('Unknown plugin parameter: ' . $key);
             }
         }
         $instance->enable();
         $this->plugins[$className] = $instance;
         $this->bot->getApplication()->getLogger()->info('Plugin initialized: ' . $className);
     } catch (\Exception $exception) {
         throw new \Exception('Error in loading plugin "' . $className . '": ' . $exception->getMessage());
     }
 }