@since 1.0

{@inheritDoc}
331459
public function fetch( $id ) {

		if ( $this->contains( $id ) ) {
			$this->cacheHits++;
			return $this->moveToMostRecentlyUsedPosition( $id );
		}

		$this->cacheMisses++;
		return false;
	}
432009
public function execute()
    {
        $db = $this->dbHandle;
        $db->/** @scrutinizer ignore-call */
        sqliteCreateFunction('log', 'log', 1);
        $sql = '
		INSERT INTO inverse_document_frequency (term, inverseDocumentFrequency)
		SELECT DISTINCT term, (1+(log(:documentCount / COUNT(documentPath) + 1))) AS inverseDocumentFrequency
					  FROM term_count
				  GROUP BY term
		';

        if (!$stmt = $db->prepare($sql)) {
            $errorInfo = $db->errorInfo();
            $errorMsg = $errorInfo[2];
            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
        }
        $stmt->bindValue(':documentCount', $this->documentCount);
        $result = $stmt->execute();
        if ($result === false) {
            $errorInfo = $db->errorInfo();
            $errorMsg = $errorInfo[2];
            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
        }
    }
18177
public function commit() {
        $this->connect();
        if (1 == $this->transTimes) {
            $this->pdo->commit();
        }
        --$this->transTimes;
    }
342246
public function Bind()
	{
		if ( $this->getCount() > 0)
		{
			if ( $this->getAbstractNode(0) instanceof PathExprNode )
			{
				/**
				 * @var PathExprNode $pathExpr
				 */
				$pathExpr = $this->getAbstractNode(0);
				if ( in_array( $this->_name, FuncNode::$s_aggregates ) && $this->_ns == XmlReservedNs::xQueryFunc )
				{
					$pathExpr->Unordered = true;
				}
			}
		}
		parent::Bind();
	}
454169
public function setValue($value) : void
    {
        if (is_object($value) && !($value instanceof ArrayObject)) {
            $this->class = $value;
            if (isset($this->value)) {
                $old = clone $this->value;
                $work = clone $value;
                if ($work instanceof JsonSerializable) {
                    $work = $work->jsonSerialize();
                }
                foreach ($work as $prop => $status) {
                    $value->$prop = isset($old->$prop) ? $old->$prop : false;
                }
            }
            $this->value = $value;
        }
        if (!isset($this->value)) {
            $this->value = clone $this->class;
        }
        if (is_array($value) || $value instanceof ArrayObject) {
            $work = clone $this->value;
            if ($work instanceof JsonSerializable) {
                $work = $work->jsonSerialize();
            }
            foreach ($work as $prop => $status) {
                $this->value->$prop = false;
            }
            foreach ($value as $prop) {
                if (is_string($prop) && $this->hasBit($prop) && isset($this->value->$prop)) {
                    $this->value->$prop = true;
                }
            }
        }
        $found = [];
        foreach ((array)$this as $element) {
            if ($element->getElement() instanceof Hidden) {
                continue;
            }
            $check = $element->getElement()->getValue();
            if (isset($this->value->$check) && $this->value->$check) {
                $element->getElement()->check();
            } else {
                $element->getElement()->check(false);
            }
            $found[] = $check;
        }
    }
610758
public function delete( $id ) {

		$container = $this->read( $id );

		foreach ( $container->getLinkedList() as $linkedId ) {
			$key = $this->getKey( (string)$linkedId );
			$this->cache->delete( $key );
			$this->internalCache->delete( $key );
		}

		$this->cache->delete( $this->getKey( $id ) );
		$this->internalCache->delete( $this->getKey( $id ) );
	}
1318578
public function find($id = NULL)
    {
        if ($id !== NULL)
        {
            $data             = $this->getData();
            $this->currentId  = $id;
            $this->currentKey = $this->getRowKey($id);
            foreach ($data[$this->currentKey] as $field => $value)
            {
                $this->setField($field, $value);
            }
        }
        else
        {
            $this->limit(1)->findAll();
            $data = $this->data;
            if (count($data))
            {
                foreach ($data[0] as $field => $value)
                {
                    $this->setField($field, $value);
                }

                $this->currentId  = $this->getField('id');
                $this->currentKey = $this->getRowKey($this->currentId);
            }
        }
        return clone $this;
    }
1240592
public function current()
    {
        $k = key($this->ids);
        if (null === $k) {
            return false;
        }

        if (count($this->ids) == 1) {
            return $this;
        }

        if (!isset($this->_ich[$k])) {
            $this->_ich[$k] = new self($this->doc, array($k => $this->ids[$k]));
        }

        return $this->_ich[$k];
    }
1346618
public function forceEndDocument(): void
    {
        if (empty($this->stack)) {
            return;
        }

        $key = $this->keys;
        for ($i = $this->level - 1; $i > 0; --$i) {
            $value = array_pop($this->stack);
            //value
            $obj = array_pop($this->stack);
            if (!empty($key[$i])) {
                $obj[$key[$i]] = $value;
                $key[$i] = null;
            } else {
                $obj[] = $value;
            }
            if ($i > 1) {
                $this->stack[] = $obj;
            } else {
                $this->json = $obj;
            }
        }
    }
720248
public function init(Document $document)
	{
		$this->hashId = $this->getHashId($document, $this->serviceLocator);
		$this->title = $document->getTitle();
		$this->price = $this->getPrice($document);
		$this->priceFormatted = $this->getPriceFormatted($document);
		$this->meta = $this->getMeta($document);
		$this->date = $this->getDateFormatted($document);
		$this->image = $this->getImage($document, $this->serviceLocator); // rimuovere
		$this->images = $this->getImages($document, $this->serviceLocator); 
		$this->content = $document->getContent();
		$this->nl2brContent = nl2br($document->getContent());
		$this->dateInsert = $document->getDateInsert()->format('Y/m/d H:i:s');
		$this->visited = $document->getVisited();

		$this->state = $document->getState();
		$this->stateFormatted = $this->getStateFormatted($document);
		
		$state = $document->getState();
		$this->isActive = Document::DOCUMENT_STATE_ACTIVE == $state;
		$this->isDeactive = Document::DOCUMENT_STATE_DEACTIVE == $state;
		$this->isDeleted = Document::DOCUMENT_STATE_DELETED == $state;
		$this->isExpired = $this->getIsExpired($document);
		$this->cssClass = $this->isActive && !$this->isExpired ? '' : 'warning';
		$this->purpose = $this->getPurpose($document); 
		$this->mobile = $this->getMobile($document); 
		$this->hidemobile = $this->getHideMobile($document); 

		$this->location = $this->getLocation($document, $this->serviceLocator);
		$this->locationFormatted = $this->getLocationFormatted($document, $this->serviceLocator); 
		
		$this->categories = $this->getCategories($document); 
		$this->category = $this->getCategory($document); 
		$this->slug = $this->getSlug($document); 
		$this->address = $this->getAddress($document, $this->serviceLocator);
		$this->editaddress = $this->getEditAddress($document);
		$this->insert = $this->getInsertDate($document);
		
		// Some user data
		$user = $document->getUser();
		$this->userId = $this->getUserHashId($document, $this->serviceLocator);
		$this->fullname = $user->getName() . ' ' . $user->getSurname();
		
		// Some location data
		$geoname = $document->getGeoname();
		$this->longitude = null !== $geoname ? $geoname->getLongitude() : null;
		$this->latitude = null !== $geoname ? $geoname->getLatitude() : null;
		
		$this->breadcrumbs = $this->getBreadcrumbs($document);
		
		return $this;
	}
427491
public function withCache($since, $time = '+1 day')
    {
        if (!is_int($time)) {
            $time = strtotime($time);
        }

        return $this->withHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT')
            ->withModified($since)
            ->withExpires($time)
            ->withSharable(true)
            ->withMaxAge($time - time());
    }
552347
public function perform()
    {
        /** @var DocumentDeclaration $declaration */
        $declaration = $this->createDeclaration();

        foreach ($this->option('field') as $field) {
            if (strpos($field, ':') === false) {
                throw new ScaffolderException("Field definition must in 'name:type' form");
            }

            list($name, $type) = explode(':', $field);
            $declaration->addField($name, $type);
        }

        $declaration->setCollection((string)$this->option('collection'));
        $declaration->setDatabase((string)$this->option('database'));

        $this->writeDeclaration($declaration->normalizeDeclaration());

        if ($this->option('source')) {
            $this->writeDeclaration(
                $this->sourceDeclaration(
                    $this->argument('name'),
                    'document',
                    $this->getNamespace() . '\\' . $this->getClass()
                ),
                'source'
            );
        }
    }
73773
public function render()
    {
        $this->tag->addAttribute('type', 'checkbox');

        $checked = $this->arguments['checked'];
        $multiple = $this->arguments['multiple'];

        // if value was assigned an object, it's identifier will be returned
        $valueAttribute = $this->getValueAttribute(true);
        $propertyValue = null;
        if ($this->hasMappingErrorOccurred()) {
            $propertyValue = $this->getLastSubmittedFormData();
        }

        if ($checked === null && $propertyValue === null) {
            $propertyValue = $this->getPropertyValue();
        }

        if ($propertyValue instanceof \Traversable) {
            $propertyValue = iterator_to_array($propertyValue);
        }
        if (is_array($propertyValue)) {
            if ($checked === null) {
                $checked = false;
                foreach ($propertyValue as $value) {
                    if (TypeHandling::isSimpleType(TypeHandling::getTypeForValue($value))) {
                        $checked = $valueAttribute === $value;
                    } else {
                        // assume an entity
                        $checked = $valueAttribute === $this->persistenceManager->getIdentifierByObject($value);
                    }
                    if ($checked === true) {
                        break;
                    }
                }
            }
            $this->arguments['multiple'] = true;
        } elseif (!$multiple && $propertyValue !== null) {
            $checked = (boolean)$propertyValue === (boolean)$valueAttribute;
        }

        $nameAttribute = $this->getName();
        if (isset($this->arguments['multiple']) && $this->arguments['multiple'] === true) {
            $nameAttribute .= '[]';
        }

        $this->registerFieldNameForFormTokenGeneration($nameAttribute);
        $this->tag->addAttribute('name', $nameAttribute);
        $this->tag->addAttribute('value', $valueAttribute);
        if ($checked === true) {
            $this->tag->addAttribute('checked', '');
        }

        $this->addAdditionalIdentityPropertiesIfNeeded();
        $this->setErrorClassAttribute();

        $this->renderHiddenFieldForEmptyValue();
        return $this->tag->render();
    }
555995
public function setFrom($from)
    {
        if ($from === null) {
            throw new BuildException("this mapper requires a 'from' attribute");
        }

        $index = strrpos($from, '*');

        if ($index === false) {
            $this->fromPrefix = $from;
            $this->fromPostfix = "";
        } else {
            $this->fromPrefix = substr($from, 0, $index);
            $this->fromPostfix = substr($from, $index + 1);
            $this->fromContainsStar = true;
        }
        $this->prefixLength = strlen($this->fromPrefix);
        $this->postfixLength = strlen($this->fromPostfix);
    }
1066557
public function init()
	{
		list($name,$id)=$this->resolveNameID();
		if(isset($this->htmlOptions['id']))
			$id=$this->htmlOptions['id'];
		else
			$this->htmlOptions['id']=$id;
		if(isset($this->htmlOptions['name']))
			$name=$this->htmlOptions['name'];

		$this->registerClientScript();

		if($this->hasModel())
		{
			$field=$this->textArea ? 'activeTextArea' : 'activeTextField';
			echo CHtml::$field($this->model,$this->attribute,$this->htmlOptions);
		}
		else
		{
			$field=$this->textArea ? 'textArea' : 'textField';
			echo CHtml::$field($name,$this->value,$this->htmlOptions);
		}
	}
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;
                                }
                            }
                        }
                    }
                }
            });
        }
    }
3113
public function execute($n)
    {
        $stack = array();
        $i = 0;
        $total = count($this->tokens);
        while ($i < $total) {
            $next = $this->tokens[$i];
            $i++;
            if ($next[0] === 'var') {
                $stack[] = $n;
                continue;
            } elseif ($next[0] === 'value') {
                $stack[] = $next[1];
                continue;
            }

            // Only operators left.
            switch ($next[1]) {
                case '%':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 % $v2;
                    break;

                case '||':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 || $v2;
                    break;

                case '&&':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 && $v2;
                    break;

                case '<':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 < $v2;
                    break;

                case '<=':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 <= $v2;
                    break;

                case '>':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 > $v2;
                    break;

                case '>=':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 >= $v2;
                    break;

                case '!=':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 != $v2;
                    break;

                case '==':
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 == $v2;
                    break;

                case '?:':
                    $v3 = array_pop($stack);
                    $v2 = array_pop($stack);
                    $v1 = array_pop($stack);
                    $stack[] = $v1 ? $v2 : $v3;
                    break;

                default:
                    throw new Exception(sprintf('Unknown operator "%s"', $next[1]));
            }
        }

        if (count($stack) !== 1) {
            throw new Exception('Too many values remaining on the stack');
        }

        return (int) $stack[0];
    }