/** * Add soft delete to the where clause if the entity supports it * * @param ApiInterface $entity * @param string $alias * * @return void */ public function addSoftDelete(ApiInterface $entity, $alias) { $reflectionClass = new \ReflectionClass(SoftDelete::class); $reflectionMethod = $reflectionClass->getMethod("getOptions"); $reflectionMethod->setAccessible(true); /** @var SoftDelete[] $softDeleteBehaviors */ $softDeleteBehaviors = $entity->getAllBehaviorsByClassName(SoftDelete::class); foreach ($softDeleteBehaviors as $softDeleteBehavior) { $options = $reflectionMethod->invoke($softDeleteBehavior); $sql = $alias . '.' . $options["field"] . '!=?0'; $params = [$options["value"]]; $this->getCriteriaHelper()->andWhere($sql, $params); } }