{@inheritdoc}
@since 2.1.5
427478
protected function truncateDatabase()
    {
        $collections = $this->db->getDatabase()->createCommand()->listCollections();

        foreach ($collections as $collection) {
            if (in_array($collection['name'], ['system.roles', 'system.users', 'system.indexes'])) {
                // prevent deleting database auth data
                // access to 'system.indexes' is more likely to be restricted, thus indexes will be dropped manually per collection
                $this->stdout("System collection {$collection['name']} skipped.\n");
                continue;
            }

            if (in_array($collection['name'], ['system.profile', 'system.js'])) {
                // dropping of system collection is unlikely to be permitted, attempt to clear them out instead
                $this->db->getDatabase()->createCommand()->delete($collection['name'], []);
                $this->stdout("System collection {$collection['name']} truncated.\n");
                continue;
            }

            $this->db->getDatabase()->createCommand()->dropIndexes($collection['name'], '*');
            $this->db->getDatabase()->dropCollection($collection['name']);
            $this->stdout("Collection {$collection['name']} dropped.\n");
        }
    }
1113946
private function validateFieldCompatibility(FieldDefinition $interface, FieldDefinition $object): void
    {
        $this->getValidator(Inheritance::class)->validate($object, $interface);

        $this->validateArgumentExistence($interface, $object);
    }
82043
public function value($value): void
    {
        $obj = array_pop($this->stack);
        if (!empty($this->keys[$this->level])) {
            $obj[$this->keys[$this->level]] = $value;
            $this->keys[$this->level] = null;
        } else {
            $obj[] = $value;
        }
        $this->stack[] = $obj;
    }
936248
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        parent::execute($request);

        /** @var OrderPaymentInterface $payment */
        $payment = $request->getSource();
        /** @var array $model */
        $model = $request->getResult();

        $model['NOSHIPPING'] = 1;
        $model['LANDINGPAGE'] = 'Billing';
        $model['SOLUTIONTYPE'] = 'Sole';

        $order = $payment->getOrder();
        $orderTotal = $this->calculator->calculateOrderTotal($order, true);
        $paymentAmount = $payment->getAmount();

        // Add item details only if this is a full order payement.
        if (0 == bccomp($orderTotal, $paymentAmount, 2)) {
            $m = 0;
            foreach($order->getItems() as $item) {
                $model['L_PAYMENTREQUEST_0_NAME'.$m] = $item->getDesignation();
                $model['L_PAYMENTREQUEST_0_AMT'.$m] = round($item->getPrice(), 2);
                $model['L_PAYMENTREQUEST_0_QTY'.$m] = $item->getQuantity();
                $m++;
            }
            $model['PAYMENTREQUEST_0_ITEMAMT'] = round($this->calculator->calculateOrderItemsTotal($order), 2);

            $model['PAYMENTREQUEST_0_SHIPPINGAMT'] = round($this->calculator->calculateOrderShipmentTotal($order), 2);

            $taxes = $this->calculator->calculateOrderTaxesAmounts($order);
            $model['PAYMENTREQUEST_0_TAXAMT'] = round($taxes->getTotal(), 2);
        }

        $request->setResult((array) $model);
    }
157384
public function writeValueToMappingResult($value, MappingResult $mappingResult, N2nContext $n2nContext) {
		if ($this->isArray()) {
			$mapValue = $this->createEmptyValue();
			
			if ($value !== null) {
				ArgUtils::valArrayLike($value);
				foreach ($value as $key => $valueField) {
					$mapValue[$key] = $this->createMappingResult($valueField, $n2nContext);
				}
			}
			 
			$mappingResult->__set($this->getName(), $mapValue);
			return;
		}

		if ($value !== null) {
			$mappingResult->__set($this->getName(), $this->createMappingResult($value, $n2nContext));
			return;
		}
		
		$mappingResult->__set($this->getName(), null);
	}
170298
public function afterNodeCreate(NodeInterface $node)
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        /* @var $nodeEvent NodeEvent */
        $nodeEvent = array_pop($this->currentNodeAddEvents);
        $nodeEvent->setNode($node);
        $this->eventEmittingService->popContext();
        $this->eventEmittingService->add($nodeEvent);
    }
1096277
public function validateReferences()
    {
        foreach ($this->referenceMappings as $fieldName) {
            $mapping = $this->mappings[$fieldName];
            if (!empty($mapping['targetDocument']) && !ClassLoader::classExists($mapping['targetDocument'])) {
                throw MappingException::invalidTargetDocumentClass($mapping['targetDocument'], $this->name, $mapping['fieldName']);
            }
        }
    }
432831
public function hasChanged($fields)
    {
        if ($this->_snapshot === false) {
            throw new PreconditionException(['getChangedFields failed: `:model` instance is snapshot disabled', 'model' => static::class]);
        }

        /** @noinspection ForeachSourceInspection */
        foreach ((array)$fields as $field) {
            if (!isset($this->_snapshot[$field]) || $this->{$field} !== $this->_snapshot[$field]) {
                return true;
            }
        }

        return false;
    }
1001449
public function process(ContainerBuilder $container)
    {
        $parameterBag = $container->getParameterBag();

        foreach ($container->getDefinitions() as $id => $definition) {
            try {
                $definition->setClass($parameterBag->resolveValue($definition->getClass()));
                $definition->setFile($parameterBag->resolveValue($definition->getFile()));
                $definition->setArguments($parameterBag->resolveValue($definition->getArguments()));

                $factory = $definition->getFactory();

                if (is_array($factory) && isset($factory[0])) {
                    $factory[0] = $parameterBag->resolveValue($factory[0]);
                    $definition->setFactory($factory);
                }

                $calls = array();
                foreach ($definition->getMethodCalls() as $name => $arguments) {
                    $calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
                }
                $definition->setMethodCalls($calls);

                $definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
            } catch (ParameterNotFoundException $e) {
                $e->setSourceId($id);

                throw $e;
            }
        }

        $aliases = array();
        foreach ($container->getAliases() as $name => $target) {
            $aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
        }
        $container->setAliases($aliases);

        $parameterBag->resolve();
    }
1363580
public function resolve(Constraint $constraint, FormInterface $form, RuleCollection $collection)
    {
        $constraintClass = get_class($constraint);

        /** @var \Symfony\Component\Validator\Constraints\AbstractComparison $constraint */
        if ($constraintClass === GreaterThan::class) {
            $rule = new ConstraintRule(
                self::RULE_NAME,
                $constraint->value + 1, // TODO support floats
                new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
                $constraint->groups
            );
        } elseif ($constraintClass === GreaterThanOrEqual::class) {
            $rule = new ConstraintRule(
                self::RULE_NAME,
                $constraint->value,
                new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
                $constraint->groups
            );
        }
        /** @var Range $constraint */
        elseif ($constraintClass === Range::class && $constraint->min !== null) {
            $rule = new ConstraintRule(
                self::RULE_NAME,
                $constraint->min,
                new RuleMessage($constraint->minMessage, array('{{ limit }}' => $constraint->min)),
                $constraint->groups
            );
        } else {
            throw new LogicException();
        }

        $collection->set(
            self::RULE_NAME,
            $rule
        );
    }
128020
public function bind($bindObject) {
        // Loop over object and set property value
        foreach ($bindObject as $key => $value) {
            ObjectUtils::setNestedObjectProperty($value, $this, $key);
        }
    }
1348885
public static function bind($key, $object = null)
    {
        if(is_array($key))
        {
            foreach($key as $key => $object)
            {
                self::$bindings[$key] = $object;
            }
        }
        else
        {
            self::$bindings[$key] = $object;
        }
    }
279637
public function replaceReservedMethod($methodName, $context = null)
    {
        if ($this->getReservedMethodsInstance()->is($methodName)) {
            if ($context !== null) {
                $methodKey = $methodName . '_' . $context;
                if (!array_key_exists($methodKey, $this->replacedReservedMethods)) {
                    $this->replacedReservedMethods[$methodKey] = 0;
                } else {
                    $this->replacedReservedMethods[$methodKey]++;
                }
                return '_' . $methodName . ($this->replacedReservedMethods[$methodKey] ? '_' . $this->replacedReservedMethods[$methodKey] : '');
            } else {
                return '_' . $methodName;
            }
        } else {
            return $methodName;
        }
    }
933495
public function saved(BlockTypeInterface $blockType)
    {
        if ($blockType->isDirty('is_shared')) {
            DynamicBlock::fromTable($blockType->getAttribute('identifier'))->update(['is_shared' => $blockType->getAttribute('is_shared')]);
        }

        if ($blockType->isDirty('identifier')) {
            DynamicBlock::fromTable($blockType->getAttribute('identifier'))->update(['is_shared' => $blockType->getAttribute('is_shared')]);
        }

        if (! $blockType->dynamicTableExists()) {
            $blockType->createTable();
        }
    }
934420
public function execute()
    {
        $response = $this->client->allDocs(100);
        $lastKey = null;

        do {
            if ($response->status !== 200) {
                throw new \RuntimeException('Error while migrating at offset '.$offset);
            }

            $bulkUpdater = $this->client->createBulkUpdater();
            foreach ($response->body['rows'] as $row) {
                $doc = $this->migrate($row['doc']);
                if ($doc) {
                    $bulkUpdater->updateDocument($doc);
                }
                $lastKey = $row['key'];
            }

            $bulkUpdater->execute();
            $response = $this->client->allDocs(100, $lastKey);
        } while (count($response->body['rows']) > 1);
    }
1262835
public function init()
    {
        parent::init();

        self::$plugin = $this;

        if (!Craft::$app->getRequest()->getIsCpRequest()) {
            return;
        }

        // Register Components (Services)
        $this->setComponents([
            'singlesList' => SinglesList::class,
        ]);

        // Modified the entry index sources
        Event::on(Entry::class, Element::EVENT_REGISTER_SOURCES, function(RegisterElementSourcesEvent $event) {
            
            // Have we enabled the plugin?
            if ($this->getSettings()->expandSingles) {

                // Are there any Singles at all?
                foreach ($event->sources as $source) {
                    if (array_key_exists('key', $source) && $source['key'] === 'singles') {
                        $this->singlesList->createSinglesList($event);
                    }
                }
            }
        });

        // Hook onto a special hook from Redactor - it handles singles a little differently!
        if (class_exists(RedactorField::class)) {
            Event::on(RedactorField::class, RedactorField::EVENT_REGISTER_LINK_OPTIONS, function(RegisterLinkOptionsEvent $event) {
                
                // Have we enabled the plugin?
                if ($this->getSettings()->expandSingles) {

                    foreach ($event->linkOptions as $i => $linkOption) {

                        // Only apply this for entries, and if there are any singles
                        if ($linkOption['refHandle'] === 'entry') {
                            if (in_array('singles', $linkOption['sources'])) {
                                $modifiedSources = $this->singlesList->createSectionedSinglesList($linkOption['sources']);

                                if ($modifiedSources) {
                                    $event->linkOptions[$i]['sources'] = $modifiedSources;
                                }
                            }
                        }
                    }
                }
            });
        }
    }
790250
@Override
    public void setValue(final Object selectedItemId) {
        if (selectedItemId != null) {
            // Can happen during validation, leading to multiple database
            // queries, in order to get the caption property
            if (selectedItemId.equals(previousValue)) {
                return;
            }
            selectedValueCaption = Optional.ofNullable(getContainerProperty(selectedItemId, getItemCaptionPropertyId()))
                    .map(Property::getValue).map(String.class::cast).orElse("");
        }

        super.setValue(selectedItemId);
        previousValue = (Long) selectedItemId;
    }