/** * 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__)); } }
public function __construct($record, $items = array()) { if (is_numeric($record)) { $record = Tribe__Events__Aggregator__Records::instance()->get_by_post_id($record); } if (!in_array('Tribe__Events__Aggregator__Record__Abstract', class_parents($record))) { return false; } // Prevent it going any further if (is_wp_error($record)) { return $record; } $this->record = $record; // Prevent it going any further if (is_wp_error($items)) { return $this; } $this->activity(); if (!empty($items)) { if ('fetch' === $items) { $this->is_fetching = true; $this->items = 'fetch'; } else { $this->init_queue($items); } $this->save(); } else { $this->load_queue(); } }
/** * Reads extension metadata * * @param object $meta * @return array - the metatada configuration */ public function getExtensionMetadata($meta) { if ($meta->isMappedSuperclass) { return; // ignore mappedSuperclasses for now } $config = array(); $cmf = $this->objectManager->getMetadataFactory(); $useObjectName = $meta->name; // collect metadata from inherited classes if (null !== $meta->reflClass) { foreach (array_reverse(class_parents($meta->name)) as $parentClass) { // read only inherited mapped classes if ($cmf->hasMetadataFor($parentClass)) { $class = $this->objectManager->getClassMetadata($parentClass); $this->driver->readExtendedMetadata($class, $config); $isBaseInheritanceLevel = !$class->isInheritanceTypeNone() && !$class->parentClasses && $config; if ($isBaseInheritanceLevel) { $useObjectName = $class->name; } } } } $this->driver->readExtendedMetadata($meta, $config); if ($config) { $config['useObjectClass'] = $useObjectName; } // cache the metadata (even if it's empty) // caching empty metadata will prevent re-parsing non-existent annotations $cacheId = self::getCacheId($meta->name, $this->extensionNamespace); if ($cacheDriver = $cmf->getCacheDriver()) { $cacheDriver->save($cacheId, $config, null); } return $config; }
/** * Gets the list of the properties for an subset of the classes * * @return array Returns array of the ReflectionProperty */ public function _getReflectionProperties() { if (is_null($this->reflectionProperties)) { $this->reflectionProperties = array(); $f = false; $classes = array(); foreach (array_reverse(class_parents($this)) as $class) { if (!$f && !($f = is_subclass_of($class, __CLASS__))) { continue; } $classes[] = new \ReflectionClass($class); } $classes[] = new \ReflectionClass(get_class($this)); foreach ($classes as $refl) { foreach ($refl->getProperties(\ReflectionProperty::IS_PRIVATE) as $refp) { if (substr($refp->getName(), 0, 1) == '_') { continue; } /* @var $refp \ReflectionProperty */ $refp->setAccessible(true); $this->reflectionProperties[$refp->getName()] = $refp; } } } return $this->reflectionProperties; }
/** * Register a class to be used when creating validation rules * * @param string $name * @param string $class * @return \Sirius\Validation\RuleFactory */ function register($name, $class) { if (in_array('Sirius\\Validation\\Rule\\AbstractValidator', class_parents($class))) { $this->validatorsMap[$name] = $class; } return $this; }
/** * 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; }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { foreach ($container->findTaggedServiceIds('mautic.event_subscriber') as $id => $tags) { $definition = $container->findDefinition($id); $classParents = class_parents($definition->getClass()); if (!in_array(CommonSubscriber::class, $classParents)) { continue; } $definition->addMethodCall('setTemplating', [new Reference('mautic.helper.templating')]); $definition->addMethodCall('setRequest', [new Reference('request_stack')]); $definition->addMethodCall('setSecurity', [new Reference('mautic.security')]); $definition->addMethodCall('setSerializer', [new Reference('jms_serializer')]); $definition->addMethodCall('setSystemParameters', [new Parameter('mautic.parameters')]); $definition->addMethodCall('setDispatcher', [new Reference('event_dispatcher')]); $definition->addMethodCall('setTranslator', [new Reference('translator')]); $definition->addMethodCall('setEntityManager', [new Reference('doctrine.orm.entity_manager')]); $definition->addMethodCall('setRouter', [new Reference('router')]); $class = $definition->getClass(); $reflected = new \ReflectionClass($class); if ($reflected->hasProperty('logger')) { $definition->addMethodCall('setLogger', [new Reference('monolog.logger.mautic')]); } // Temporary, for development purposes if ($reflected->hasProperty('factory')) { $definition->addMethodCall('setFactory', [new Reference('mautic.factory')]); } if (in_array(WebhookSubscriberBase::class, $classParents)) { $definition->addMethodCall('setWebhookModel', [new Reference('mautic.webhook.model.webhook')]); } $definition->addMethodCall('init'); } }
static function plugins_loaded() { // Load stores early so we can confirm they're loaded correctly require_once dirname(__FILE__) . '/store.php'; do_action('keyring_load_token_stores'); $keyring = Keyring::init(); $keyring->token_store = apply_filters('keyring_token_store', defined('KEYRING__TOKEN_STORE') ? KEYRING__TOKEN_STORE : false); if (!class_exists($keyring->token_store) || !in_array('Keyring_Store', class_parents($keyring->token_store))) { wp_die(sprintf(__('Invalid <code>KEYRING__TOKEN_STORE</code> specified. Please make sure <code>KEYRING__TOKEN_STORE</code> is set to a valid classname for handling token storage in <code>%s</code> (or <code>wp-config.php</code>)', 'keyring'), __FILE__)); } // Load base token and service definitions + core services require_once dirname(__FILE__) . '/token.php'; require_once dirname(__FILE__) . '/service.php'; // Triggers a load of all core + extended service definitions // Initiate Keyring add_action('init', array('Keyring', 'init'), 1); // Load external Services (plugins etc should hook to this to define new ones/extensions) add_action('init', function () { do_action('keyring_load_services'); }, 2); /** * And trigger request handlers, which plugins and extended Services use to handle UI, * redirects, errors etc. * @see ::request_handlers() */ add_action('admin_init', array('Keyring', 'request_handlers'), 100); }
public function onControllerInit(Event $event) { $controller = $event->subject(); //Skip Auth for non app controllers. DebugKit For example //possible injection hole, but needed. if (!in_array('App\\Controller\\AppController', class_parents($controller))) { return; } $controller->loadComponent('Cookie'); $loginRedirect = '/'; if (isset($controller->request->params['prefix'])) { $loginRedirect .= $controller->request->params['prefix']; } $controller->loadComponent('Auth', ['loginAction' => ['plugin' => 'Passengers', 'controller' => 'Users', 'action' => 'signin'], 'loginRedirect' => $loginRedirect, 'logoutRedirect' => ['plugin' => 'Passengers', 'controller' => 'Users', 'action' => 'signin'], 'unauthorizedRedirect' => ['plugin' => 'Passengers', 'controller' => 'Users', 'action' => 'signin'], 'authenticate' => [AuthComponent::ALL => ['fields' => ['username' => 'username', 'password' => 'password'], 'userModel' => 'Passengers.Users', 'finder' => 'active'], 'Form', 'Passengers.Cookie']]); $authorizeConfig = []; if ($authorizers = Configure::read('Passengers.authorizers')) { foreach ($authorizers as $key => $authorizer) { if (isset($authorizer['className']) && ($plugin = pluginSplit($authorizer['className'])[0])) { if (!Plugin::loaded($plugin)) { continue; } } $authorizeConfig[$key] = $authorizer; } } $forceAuth = Configure::read('App.force_user_auth'); if ($forceAuth && empty($authorizeConfig)) { $authorizeConfig[] = 'Controller'; } $controller->Auth->config('authorize', array(AuthComponent::ALL => ['actionPath' => 'controllers/']) + $authorizeConfig); $this->_setUser($controller); $controller->loadComponent('Passengers.AuthUser'); $controller->viewBuilder()->helpers(['Passengers.AuthUser']); }
static function class_parents($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_parents')) { $autoload = array(); while (false !== ($class = get_parent_class($class))) { $autoload[$class] = $class; } /**/ } else { $autoload = class_parents($c, false); /**/ } foreach ($autoload as $c) { isset(self::$us2ns[$a = strtolower($c)]) && ($autoload[$c] = self::$us2ns[$a]); } return $autoload; }
/** * @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 . "'"); } } }
public function registerMetaAttributes($shortCut, $classname) { if (last(array_values(class_parents($classname))) !== MetaAttributes::class) { throw new \InvalidArgumentException('Meta attribute but be extended from ' . MetaAttributes::class . '. ' . $classname . ' was given.'); } $this->metas[$shortCut] = $classname; }
/** * @param \Nette\DI\Container $dic * @throws MemberAccessException * @internal */ public function injectComponentFactories(Nette\DI\Container $dic) { if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) { throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.'); } $this->autowireComponentFactoriesLocator = $dic; $storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage'); $cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireComponentFactories'); if ($cache->load($presenterClass = get_class($this)) !== NULL) { return; } $ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter']; $rc = new ClassType($this); foreach ($rc->getMethods() as $method) { if (in_array($method->getDeclaringClass()->getName(), $ignore, TRUE) || !Strings::startsWith($method->getName(), 'createComponent')) { continue; } foreach ($method->getParameters() as $parameter) { if (!($class = $parameter->getClassName())) { // has object type hint continue; } if (!$this->findByTypeForFactory($class) && !$parameter->allowsNull()) { throw new MissingServiceException("No service of type {$class} found. Make sure the type hint in {$method} is written correctly and service of this type is registered."); } } } $files = array_map(function ($class) { return ClassType::from($class)->getFileName(); }, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore)); $files[] = ClassType::from($this->autowireComponentFactoriesLocator)->getFileName(); $cache->save($presenterClass, TRUE, [$cache::FILES => $files]); }
private static function check_lib($lib) { if (!\class_exists($lib) || !\is_array($parents = \class_parents($lib)) || !\array_search('LIB\\lib', $parents)) { return false; } return true; }
/** * Reads extension metadata * * @param ClassMetadataInfo $meta * @return array - the metatada configuration */ public function getExtensionMetadata(ClassMetadataInfo $meta) { if ($meta->isMappedSuperclass) { return; // ignore mappedSuperclasses for now } $config = array(); // collect metadata from inherited classes foreach (array_reverse(class_parents($meta->name)) as $parentClass) { // read only inherited mapped classes if ($this->_em->getMetadataFactory()->hasMetadataFor($parentClass)) { $this->_driver->readExtendedMetadata($this->_em->getClassMetadata($parentClass), $config); } } $this->_driver->readExtendedMetadata($meta, $config); $this->_driver->validateFullMetadata($meta, $config); if ($config) { // cache the metadata $cacheId = self::getCacheId($meta->name, $this->_extensionNamespace); if ($cacheDriver = $this->_em->getMetadataFactory()->getCacheDriver()) { $cacheDriver->save($cacheId, $config, null); } } return $config; }
/** * Checking if static proxy is a really static proxy of StaticalProxy. * * @param string $static * * @return bool */ public function isStaticProxy(string $static) : bool { if (class_exists($static)) { return array_key_exists(StaticalProxy::class, class_parents($static)); } return false; }
/** * Set an option value * * @param string $propertyName * @param mixed $propertyValue * @throws ezcBasePropertyNotFoundException * If a property is not defined in this class * @throws ezcBaseValueException * if $value is not correct for the property $name * @throws ezcBaseInvalidParentClassException * if the class name passed as replacement for any of the built-in * classes do not inherit from the built-in classes. * @return void */ public function __set($propertyName, $propertyValue) { $parentClassMap = array('tableClassName' => 'ezcDbSchemaTable', 'fieldClassName' => 'ezcDbSchemaField', 'indexClassName' => 'ezcDbSchemaIndex', 'indexFieldClassName' => 'ezcDbSchemaIndexField'); switch ($propertyName) { case 'tableClassName': case 'fieldClassName': case 'indexClassName': case 'indexFieldClassName': if (!is_string($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'string that contains a class name'); } // Check if the passed classname actually implements the // correct parent class. if ($parentClassMap[$propertyName] !== $propertyValue && !in_array($parentClassMap[$propertyName], class_parents($propertyValue))) { throw new ezcBaseInvalidParentClassException($parentClassMap[$propertyName], $propertyValue); } $this->properties[$propertyName] = $propertyValue; break; case 'tableNamePrefix': if (!is_string($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'string'); } $this->properties[$propertyName] = $propertyValue; break; default: throw new ezcBasePropertyNotFoundException($propertyName); break; } }
public function createController() { // Check Class if (class_exists($this->controller)) { $parents = class_parents($this->controller); // Check Extend if (in_array("Controller", $parents)) { if (method_exists($this->controller, $this->action)) { return new $this->controller($this->action, $this->request); } else { // Method Does Not Exists / Not Found! echo '<h1>Method Not Found</h1>'; return; } } else { // Base Controller Does Not Exists / Not Found! echo '<h1>Base Controller Not Found</h1>'; return; } } else { // Controller Class Does Not Exists / Not Found! echo '<h1>Controller Class Not Found</h1>'; return; } }
/** * Determine if this is a extended version of a base object * @param Object $obj The object to check * @access Private * @return Bool */ private function isObject($obj) : bool { if (!is_object($obj) || !in_array('JEBaseObject', class_parents($obj))) { return false; } return true; }
public function ctrlClassInheritsMaster() { if (in_array("MasterController", class_parents($this->ctrlClass))) { return true; } return false; }
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"); }
public function isResource($resourceName) { if (class_exists($resourceName)) { return in_array('ANich\\Chomp\\Resource', class_parents($resourceName)); } return false; }
/** * @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]; }
/** * Execute vlcwrapper initialization on the first request */ private function lazyInit() { if ($this->_initialized === false) { $options = $this->options; $adapterConf = $options->get('adapter', new Zend_Config(array())); $adapter = $adapterConf->get('name', "X_Vlc_Adapter_" . (X_Env::isWindows() ? 'Windows' : 'Linux')); X_Debug::i("Adapter: {$adapter}"); $this->adapter = new $adapter($options); $commanderConf = $options->get('commander', new Zend_Config(array())); $commander = $commanderConf->get('name', ''); $commanderPath = $commanderConf->get('path', ''); if ($commanderPath != '' && file_exists($commanderPath)) { X_Debug::i("Including commanderPath: {$commanderPath}"); include_once $commanderPath; } if (class_exists($commander, true) && array_key_exists('X_Vlc_Commander', class_parents($commander))) { X_Debug::i("Commander: {$commander}"); $commander = new $commander($options); $this->adapter->setCommander($commander); } else { X_Debug::w("Commander: no selection"); } $this->_conf_vlcArgs = $options->get('args', "{%source%} --play-and-exit --sout=\"#{%profile%}:{%output%}\" --sout-keep {%subtitles%} {%audio%} {%filters%}"); $this->_conf_vlcPath = $options->get('path', "vlc"); $this->_initialized = true; } }
/** * {@inheritDoc} */ public function getParentClasses($class) { if (!class_exists($class)) { throw MappingException::nonExistingClass($class); } return class_parents($class); }
/** * Runs through the validation required by * each form element. * @param object $addable Object that extends from \HtmlForm\Abstracts\Addable * @return array Found errors */ public function validate($addable) { foreach ($addable->elements as $element) { $classes = class_parents($element); // no validation needed if (in_array("HtmlForm\\Elements\\Parents\\Html", $classes)) { continue; } if (in_array("HtmlForm\\Abstracts\\Addable", $classes)) { // validate this addable (fieldset) $moreErrors = $this->validate($element); } else { $class = $this->findclass($element); if ($class == "honeypot") { $value = $element->getRawValue(); $this->honeypot($value); continue; } // validate this element $elementErrors = $element->validate(); // add new errors to the list $this->errors = array_merge($this->errors, $elementErrors); } } return empty($this->errors); }
public function createController() { if ($this->backRequest == true && file_exists("back/" . $this->controllerName . ".class.php")) { require_once "back/" . $this->controllerName . ".class.php"; } else { if (file_exists("views/" . $this->controllerName . ".class.php")) { require_once "views/" . $this->controllerName . ".class.php"; } else { require_once "views/error.php"; return; } } if (class_exists($this->controllerClass)) { $parents = class_parents($this->controllerClass); if (in_array("BaseController", $parents)) { if (method_exists($this->controllerClass, $this->action)) { return new $this->controllerClass($this->action, $this->urlValues); } else { require_once "views/error.php"; return new ErrorController("badurl", $this->urlValues); } } else { require_once "views/error.php"; return new ErrorController("badurl", $this->urlValues); } } else { require_once "views/error.php"; return; } }
/** * 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); } }
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)); }
public function parentsOf($class) { if (false === isset($this->parents[$class])) { $this->parents[$class] = class_parents($class); } return $this->parents[$class]; }