MongoDBRef::isRef PHP Метод

isRef() публичный статический Метод

It merely checks that $ref is in valid database reference format (in that it is an object or array with $ref and $id fields).
public static isRef ( mixed $ref ) : boolean
$ref mixed Array or object to check
Результат boolean Returns true if $ref is a reference
    public static function isRef($ref)
    {
        $check = (array) $ref;
        return array_key_exists(static::$refKey, $check) && array_key_exists(static::$idKey, $check);
    }

Usage Example

Пример #1
0
 public function testShouldReturnLazyLoadingCursor()
 {
     $parentCategory = new Category();
     $parentCategory->setName('Parent category');
     $parentCategory->setDesc('Parent category');
     $parentCategory->save();
     for ($i = 0; $i < 10; $i++) {
         $category = new Category();
         $category->setName('Category ' . $i);
         $category->setDesc('Category ' . $i . ' desc');
         $category->setCategory($parentCategory);
         $category->save();
     }
     Category::enableLazyLoading();
     $categories = Category::find([['category' => ['$ne' => null]]]);
     $this->assertInstanceOf('\\Vegas\\Odm\\Collection\\LazyLoadingCursor', $categories);
     foreach ($categories as $category) {
         $this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category);
         $this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category->getCategory());
     }
     $categories = Category::find([['category' => ['$ne' => null]]]);
     $this->assertInstanceOf('\\Vegas\\Odm\\Collection\\LazyLoadingCursor', $categories);
     foreach ($categories as $category) {
         $this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category);
         $reflectionClass = new \ReflectionClass(get_class($category));
         $categoryProperty = $reflectionClass->getProperty('category');
         $categoryProperty->setAccessible(true);
         $this->assertTrue(\MongoDBRef::isRef($categoryProperty->getValue($category)));
     }
 }
All Usage Examples Of MongoDBRef::isRef