Elastica\Type\Mapping::create PHP Method

create() public static method

Creates a mapping object.
public static create ( array | Mapping $mapping ) : self
$mapping array | Mapping Mapping object or properties array
return self
    public static function create($mapping)
    {
        if (is_array($mapping)) {
            $mappingObject = new self();
            $mappingObject->setProperties($mapping);
            return $mappingObject;
        }
        if ($mapping instanceof self) {
            return $mapping;
        }
        throw new InvalidException('Invalid object type');
    }

Usage Example

 public function testIndexMappingForParent()
 {
     $type = $this->getMockElasticaType();
     $this->indexConfigsByName['parent']['index']->expects($this->once())->method('getType')->with('a')->will($this->returnValue($type));
     $type->expects($this->once())->method('delete');
     $mapping = Mapping::create($this->indexConfigsByName['parent']['config']['mappings']['a']['properties']);
     $mapping->setParam('_parent', array('type' => 'b'));
     $type->expects($this->once())->method('setMapping')->with($mapping);
     $resetter = new Resetter($this->indexConfigsByName);
     $resetter->resetIndexType('parent', 'a');
 }
All Usage Examples Of Elastica\Type\Mapping::create