本文整理汇总了PHP中Elastica\Document::hasOpType方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::hasOpType方法的具体用法?PHP Document::hasOpType怎么用?PHP Document::hasOpType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Document
的用法示例。
在下文中一共展示了Document::hasOpType方法的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;
}