本文整理汇总了PHP中class_parents函数的典型用法代码示例。如果您正苦于以下问题:PHP class_parents函数的具体用法?PHP class_parents怎么用?PHP class_parents使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了class_parents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factory
/**
* 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__));
}
}
示例2: __construct
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();
}
}
示例3: getExtensionMetadata
/**
* 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;
}
示例4: _getReflectionProperties
/**
* 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;
}
示例5: register
/**
* 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;
}
示例6: getDependencyInterfaces
/**
* 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;
}
示例7: process
/**
* {@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');
}
}
示例8: plugins_loaded
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);
}
示例9: onControllerInit
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']);
}
示例10: class_parents
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;
}
示例11: create
/**
* @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 . "'");
}
}
}
示例12: registerMetaAttributes
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;
}
示例13: injectComponentFactories
/**
* @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]);
}
示例14: check_lib
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;
}
示例15: getExtensionMetadata
/**
* 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;
}