当前位置: 首页>>代码示例>>PHP>>正文


PHP class_uses函数代码示例

本文整理汇总了PHP中class_uses函数的典型用法代码示例。如果您正苦于以下问题:PHP class_uses函数的具体用法?PHP class_uses怎么用?PHP class_uses使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了class_uses函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: install_application

 /**
  *
  */
 public function install_application()
 {
     foreach (new \DirectoryIterator(APP_DIR . 'model') as $fi) {
         if ($fi->isDot()) {
             continue;
         }
         if ($fi->getExtension() != 'php') {
             continue;
         }
         $filename = $fi->getFilename();
         $class = ns(substr($filename, 0, -4));
         $trait = ns('ModelTrait');
         if (!self::load('model/' . $filename)) {
             trigger_error("Model file ({$filename}) could not be loaded", E_USER_ERROR);
         }
         if (!class_exists($class)) {
             trigger_error("Model file ({$filename}) found without defining class \"{$class}\"", E_USER_ERROR);
         }
         if (!in_array($trait, class_uses($class))) {
             trigger_error("Model class ({$class}) does not use required trait \"{$trait}\"", E_USER_ERROR);
         }
         echo "Integrating schema for model: {$class}\n";
         $class::integrate_schema();
     }
     die("-- Installation complete --\n");
 }
开发者ID:rommelsantor,项目名称:RawMVC,代码行数:29,代码来源:kernel.php

示例2: it_should_use_EloquenceBehavioursUuid

 /**
  * It should use Eloquence\Behaviours\Uuid;
  *
  * @test
  * @return void
  */
 public function it_should_use_EloquenceBehavioursUuid()
 {
     $traitList = class_uses($this->uuidModelWithValidation);
     $this->assertArrayHasKey("Eloquence\\Behaviours\\Uuid", $traitList);
     $this->assertClassHasAttribute('incrementing', 'Elozoya\\LaravelCommon\\UuidModelWithValidation');
     $this->assertFalse($this->uuidModelWithValidation->incrementing);
 }
开发者ID:emmanuellozoya,项目名称:laravel-common,代码行数:13,代码来源:UuidModelWithValidationTest.php

示例3: tableToArray

 /**
  * Return a simple list of entries in the table.
  *
  * May cache the results for up to 60 minutes.
  *
  * @return	array of Fluent objects
  */
 public static function tableToArray()
 {
     $me = new static();
     $cache_key = $me->cacheKey();
     // Return the array from the cache if it is present.
     if (Cache::has($cache_key)) {
         return (array) Cache::get($cache_key);
     }
     // Otherwise put the results into the cache and return them.
     $results = [];
     $query = static::all();
     // If the current model uses softDeletes then fix the
     // query to exclude those objects.
     foreach (class_uses(__CLASS__) as $traitName) {
         if ($traitName == 'SoftDeletes') {
             $query = static::whereNull('deleted_at')->get();
             break;
         }
     }
     /** @var Cacheable $row */
     foreach ($query as $row) {
         $results[$row->getIndexKey()] = $row->toFluent();
     }
     Cache::put($cache_key, $results, 60);
     return $results;
 }
开发者ID:delatbabel,项目名称:keylists,代码行数:33,代码来源:Cacheable.php

示例4: testTraitAndInterface

 /**
  * Checks the object uses the correct trait, and
  * implements the correct interface.
  *
  * @author Daniel Sherman
  * @test
  */
 public function testTraitAndInterface()
 {
     $msg = 'the object does not implement the correct interface';
     $this->assertInstanceOf('Flair\\Configuration\\SetsInterface', self::$obj, $msg);
     $msg = 'the object does not use the correct trait';
     $this->assertContains('Flair\\Configuration\\SetsTrait', class_uses(self::$obj), $msg);
 }
开发者ID:flairphp,项目名称:flair,代码行数:14,代码来源:SetsTraitTest.php

示例5: findExistingEntity

 /**
  * {@inheritdoc}
  */
 protected function findExistingEntity($entity, array $searchContext = [])
 {
     $entityName = ClassUtils::getClass($entity);
     $identifier = $this->databaseHelper->getIdentifier($entity);
     $existingEntity = null;
     // find by identifier
     if ($identifier) {
         $existingEntity = $this->databaseHelper->find($entityName, $identifier);
     }
     // find by identity fields
     if (!$existingEntity && (!$searchContext || $this->databaseHelper->getIdentifier(current($searchContext)))) {
         $identityValues = $searchContext;
         $usedTraits = class_uses($entityName);
         if ($this->context->hasOption('channel') && in_array(self::TARGET_TRAIT, $usedTraits)) {
             $channel = $this->databaseHelper->findOneBy('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel', ['id' => $this->context->getOption('channel')]);
             $identityValues['channel'] = $channel;
         }
         $identityValues += $this->fieldHelper->getIdentityValues($entity);
         $existingEntity = $this->findEntityByIdentityValues($entityName, $identityValues);
     }
     if ($existingEntity && !$identifier) {
         $identifier = $this->databaseHelper->getIdentifier($existingEntity);
         $identifierName = $this->databaseHelper->getIdentifierFieldName($entity);
         $this->fieldHelper->setObjectValue($entity, $identifierName, $identifier);
     }
     return $existingEntity;
 }
开发者ID:antrampa,项目名称:crm,代码行数:30,代码来源:DefaultMagentoImportStrategy.php

示例6: isTranslatable

 /**
  * Check if $object is translatable.
  *
  * @param mixed $object
  *
  * @return bool
  */
 public function isTranslatable($object)
 {
     if ($object === null) {
         return false;
     }
     if (function_exists('class_uses')) {
         $traits = class_uses($object);
         if (in_array('Sonata\\TranslationBundle\\Traits\\Translatable', $traits)) {
             return true;
         }
         if (in_array('Sonata\\TranslationBundle\\Traits\\Gedmo\\PersonalTranslatable', $traits)) {
             return true;
         }
     }
     $objectInterfaces = class_implements($object);
     foreach ($this->getSupportedInterfaces() as $interface) {
         if (in_array($interface, $objectInterfaces)) {
             return true;
         }
     }
     foreach ($this->getSupportedModels() as $model) {
         if ($object instanceof $model) {
             return true;
         }
     }
     return false;
 }
开发者ID:andrewtch,项目名称:SonataTranslationBundle,代码行数:34,代码来源:TranslatableChecker.php

示例7: formatValue

 private function formatValue($value)
 {
     if (is_scalar($value)) {
         return $value;
         // If the object uses this trait
     } elseif (is_a($value, 'Doctrine\\ODM\\MongoDB\\PersistentCollection')) {
         $prop = [];
         foreach ($value as $k => $v) {
             $prop[$k] = $this->formatValue($v);
         }
         return $prop;
         // If it's a Date, convert to unix timestamp
     } elseif (is_a($value, 'Date')) {
         return $value->getTimestamp();
         // Otherwise leave a note that this type is not formatted
         // So that I can add formatting for this missed class
     } elseif (is_array($value)) {
         return $value;
     } elseif (in_array(__TRAIT__, class_uses(get_class($value))) && method_exists($value, 'toStdClass')) {
         return $value->toStdClass();
         // If it's a collection, format each value
     } else {
         return 'Not formatted in DocumentSerializer: ' . get_class($value);
     }
 }
开发者ID:JonathanConner,项目名称:SocialNet,代码行数:25,代码来源:DocumentSerializer.php

示例8: actionForStringDelete

 /**
  * Get action delete for translation name
  * @return string Name
  */
 public function actionForStringDelete()
 {
     if (in_array('Illuminate\\Database\\Eloquent\\SoftDeletes', class_uses($this->entity))) {
         return 'archive';
     }
     return 'delete';
 }
开发者ID:simondubois,项目名称:budget,代码行数:11,代码来源:Event.php

示例9: __construct

 public function __construct($route, $app)
 {
     $this->app = $app;
     $this->route = $route;
     static::$instance = $this;
     //init use trait
     foreach (class_uses($this) as $_trait) {
         $_method = str_replace('\\', '_', $_trait);
         if (method_exists($this, $_method)) {
             $this->{$_method}();
         }
     }
     //load from app
     if (is_null($this->response)) {
         $this->response = $this->app->response;
     }
     if (is_null($this->request)) {
         $this->request = $this->app->request;
     }
     //run
     $r = $this->exec($this->route[1], true, true);
     //back to app
     $this->app->response = $this->response;
     return $r;
 }
开发者ID:urn2,项目名称:nx,代码行数:25,代码来源:controller.php

示例10: classUses

 /**
  * 
  * @param mixed $class
  * @param string $trait
  * @param boolean $recursive
  * @return boolean
  */
 public static function classUses($class, $trait, $recursive = true)
 {
     if (!\is_object($class) && !\is_string($class)) {
         return false;
     }
     $traits = \class_uses($class);
     if ($recursive) {
         $parent = \get_parent_class($class);
         while ($parent !== false) {
             $traits = \array_merge($traits, \class_uses($parent));
             $parent = \get_parent_class($parent);
         }
     }
     if (!is_array($trait)) {
         $trait = (array) $trait;
     }
     foreach ($traits as $k => $t) {
         if (\in_array($t, $trait)) {
             return true;
         }
         if (self::classUses($t, $trait)) {
             return true;
         }
         unset($traits[$k]);
     }
     return false;
 }
开发者ID:jgswift,项目名称:qtil,代码行数:34,代码来源:ReflectorUtil.php

示例11: eliminar2Action

 /**
  * @Route("eliminar2/")
  * @Template("TapirBaseBundle:Default:eliminar2.html.twig")
  * @Sensio\Bundle\FrameworkExtraBundle\Configuration\Method("POST")
  */
 public function eliminar2Action(Request $request)
 {
     $id = $this->ObtenerVariable($request, 'id');
     $form = $this->CrearFormEliminar($id);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getEm();
         $entity = $em->getRepository($this->VendorName . $this->BundleName . 'Bundle:' . $this->EntityName)->find($id);
         if (in_array('Tapir\\BaseBundle\\Entity\\Suprimible', class_uses($entity))) {
             // Es suprimible (soft-deletable), lo marco como borrado, pero no lo borro
             $entity->Suprimir();
             $em->persist($entity);
             $em->flush();
             $this->get('session')->getFlashBag()->add('info', 'Se suprimió el elemento "' . $entity . '".');
             return $this->afterEliminar($request, $entity, true);
         } else {
             if (in_array('Tapir\\BaseBundle\\Entity\\Eliminable', class_uses($entity))) {
                 // Es eliminable... lo elimino de verdad
                 $em->remove($entity);
                 $em->flush();
                 $this->get('session')->getFlashBag()->add('info', 'Se eliminó el elemento "' . $entity . '".');
                 return $this->afterEliminar($request, $entity, true);
             } else {
                 // No es eliminable ni suprimible... no se puede borrar
                 $this->get('session')->getFlashBag()->add('info', 'No se puede eliminar el elemento "' . $entity . '".');
             }
         }
     }
     return $this->afterEliminar($request, $entity);
 }
开发者ID:alediazrc,项目名称:yacare,代码行数:35,代码来源:ConEliminar.php

示例12: testConstruct

 /**
  * Checks the object uses the correct trait, and
  * implements the correct interface.
  *
  * @author Daniel Sherman
  * @test
  * @covers ::__construct
  */
 public function testConstruct()
 {
     $msg = 'the object does not implement the correct interface';
     $this->assertInstanceOf('Flair\\Validation\\RuleMessageInterface', self::$obj, $msg);
     $msg = 'the object does not use the correct trait';
     $this->assertContains('Flair\\Validation\\RuleMessageTrait', class_uses(self::$obj), $msg);
 }
开发者ID:flairphp,项目名称:flair,代码行数:15,代码来源:RuleMessageTraitTest.php

示例13: testModelUsesTraits

 /**
  * Test that the Model uses the traits and in the right order.
  */
 public function testModelUsesTraits()
 {
     // Get the traits off the model
     $traits = function_exists('class_uses_recursive') ? class_uses_recursive(get_class($this->model)) : class_uses(get_class($this->model));
     // Check Model uses the Soft Deleting trait
     $this->assertContains('Esensi\\Model\\Traits\\SoftDeletingModelTrait', $traits);
 }
开发者ID:esensi,项目名称:model,代码行数:10,代码来源:SoftModelTest.php

示例14: registerRouterMacro

 /**
  * Register the custom router macro.
  */
 protected function registerRouterMacro()
 {
     $this->app['router']->macro('fakeIdModel', function ($key, $class, Closure $callback = null) {
         $this->bind($key, function ($value) use($key, $class, $callback) {
             if (is_null($value)) {
                 return;
             }
             // For model binders, we will attempt to retrieve the models using the first
             // method on the model instance. If we cannot retrieve the models we'll
             // throw a not found exception otherwise we will return the instance.
             $instance = $this->container->make($class);
             // Decode FakeId first if applicable.
             if (in_array('Propaganistas\\LaravelFakeId\\FakeIdTrait', class_uses($class))) {
                 $value = $this->container->make('fakeid')->decode($value);
             }
             if ($model = $instance->where($instance->getRouteKeyName(), $value)->first()) {
                 return $model;
             }
             // If a callback was supplied to the method we will call that to determine
             // what we should do when the model is not found. This just gives these
             // developer a little greater flexibility to decide what will happen.
             if ($callback instanceof Closure) {
                 return call_user_func($callback, $value);
             }
             throw new NotFoundHttpException();
         });
     });
 }
开发者ID:propaganistas,项目名称:laravel-fakeid,代码行数:31,代码来源:FakeIdServiceProvider.php

示例15: getResourceAttributes

 /**
  * Returns attributes for the resource
  *
  * @return mixed[]
  */
 public function getResourceAttributes()
 {
     $attributes = $this->attributesToArray();
     // detect any translated attributes
     if (in_array(config('jsonapi.encoding.translatable_trait'), class_uses($this))) {
         foreach ($this->translatedAttributes as $key) {
             $attributes[$key] = $this->{$key};
         }
     }
     // unset primary key field
     unset($attributes[$this->getKeyName()]);
     // unset reserved fieldname "type"
     // reset it as modelname-type if that is not in use yet
     if (array_key_exists('type', $attributes)) {
         $typeRecast = Str::snake(class_basename($this) . '-type', '-');
         if (!array_key_exists($typeRecast, $attributes)) {
             $attributes[$typeRecast] = $attributes['type'];
         }
         unset($attributes['type']);
     }
     // map all fieldnames to dasherized case
     foreach ($attributes as $key => $value) {
         $dasherized = str_replace('_', '-', $key);
         if ($key !== $dasherized) {
             $attributes[$dasherized] = $value;
             unset($attributes[$key]);
         }
     }
     return $attributes;
 }
开发者ID:czim,项目名称:laravel-jsonapi,代码行数:35,代码来源:JsonApiResourceEloquentTrait.php


注:本文中的class_uses函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。