本文整理匯總了PHP中Elastica\Document::getOpType方法的典型用法代碼示例。如果您正苦於以下問題:PHP Document::getOpType方法的具體用法?PHP Document::getOpType怎麽用?PHP Document::getOpType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Elastica\Document
的用法示例。
在下文中一共展示了Document::getOpType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: create
/**
* @param \Elastica\Document $document
* @param string $opType
* @return \Elastica\Bulk\Action\AbstractDocument
*/
public static function create(Document $document, $opType = null)
{
if (null === $opType && $document->hasOpType()) {
$opType = $document->getOpType();
}
switch ($opType) {
case self::OP_TYPE_DELETE:
$action = new DeleteDocument($document);
break;
case self::OP_TYPE_CREATE:
$action = new CreateDocument($document);
break;
case self::OP_TYPE_UPDATE:
$action = new UpdateDocument($document);
break;
case self::OP_TYPE_INDEX:
default:
$action = new IndexDocument($document);
break;
}
return $action;
}
示例2: create
/**
* @param \Elastica\Document|\Elastica\Script\AbstractScript $data
* @param string $opType
*
* @return static
*/
public static function create($data, $opType = null)
{
//Check type
if (!$data instanceof Document && !$data instanceof AbstractScript) {
throw new \InvalidArgumentException('The data needs to be a Document or a Script.');
}
if (null === $opType && $data->hasOpType()) {
$opType = $data->getOpType();
}
//Check that scripts can only be used for updates
if ($data instanceof AbstractScript) {
if ($opType === null) {
$opType = self::OP_TYPE_UPDATE;
} elseif ($opType != self::OP_TYPE_UPDATE) {
throw new \InvalidArgumentException('Scripts can only be used with the update operation type.');
}
}
switch ($opType) {
case self::OP_TYPE_DELETE:
$action = new DeleteDocument($data);
break;
case self::OP_TYPE_CREATE:
$action = new CreateDocument($data);
break;
case self::OP_TYPE_UPDATE:
$action = new UpdateDocument($data);
break;
case self::OP_TYPE_INDEX:
default:
$action = new IndexDocument($data);
break;
}
return $action;
}
示例3: create
/**
* @param \Elastica\Document|\Elastica\Script $data
* @param string $opType
* @return \Elastica\Bulk\Action\AbstractDocument
*/
public static function create($data, $opType = null)
{
//Check type
if (!$data instanceof Document && !$data instanceof Script) {
throw new \InvalidArgumentException("The data needs to be a Document or a Script.");
}
if (null === $opType && $data->hasOpType()) {
$opType = $data->getOpType();
}
//Check that scripts can only be used for updates
if ($data instanceof Script && isset($opType) && $opType != self::OP_TYPE_UPDATE) {
throw new \InvalidArgumentException("When performing an update action, the data needs to be a Document or a Script.");
}
switch ($opType) {
case self::OP_TYPE_DELETE:
$action = new DeleteDocument($data);
break;
case self::OP_TYPE_CREATE:
$action = new CreateDocument($data);
break;
case self::OP_TYPE_UPDATE:
$action = new UpdateDocument($data);
break;
case self::OP_TYPE_INDEX:
default:
$action = new IndexDocument($data);
break;
}
return $action;
}