Evaluate closure formatters.

@param  array   $extra
@param  array[] $insertedPKs
@param  Model   $currentParent
@return array The attributes.
556595
protected function evaluateClosureFormatters(array $extra, array $insertedPKs, Model $currentParent)
    {
        return array_map(function ($formatter) use ($insertedPKs, $currentParent) {
            return is_callable($formatter) ? $formatter($currentParent, $insertedPKs) : $formatter;
        }, $extra);
    }
1147175
private function parseLinks(
        SchemaInterface $parentSchema,
        $parentData,
        string $relationshipName,
        iterable $schemaLinks,
        bool $addSelfLink,
        bool $addRelatedLink
    ): iterable {
        $gotSelf    = false;
        $gotRelated = false;

        foreach ($schemaLinks as $name => $link) {
            \assert($link instanceof LinkInterface);
            if ($name === LinkInterface::SELF) {
                \assert($gotSelf === false);
                $gotSelf     = true;
                $addSelfLink = false;
            } elseif ($name === LinkInterface::RELATED) {
                \assert($gotRelated === false);
                $gotRelated     = true;
                $addRelatedLink = false;
            }

            yield $name => $link;
        }

        if ($addSelfLink === true) {
            $link = $parentSchema->getRelationshipSelfLink($parentData, $relationshipName);
            yield LinkInterface::SELF => $link;
            $gotSelf = true;
        }
        if ($addRelatedLink === true) {
            $link = $parentSchema->getRelationshipRelatedLink($parentData, $relationshipName);
            yield LinkInterface::RELATED => $link;
            $gotRelated = true;
        }

        // spec: check links has at least one of the following: self or related
        \assert($gotSelf || $gotRelated);
    }
892397
public function _cascadeUpdate($parentTableClassname, array $oldPrimaryKey, array $newPrimaryKey)
    {
        $this->_setupMetadata();
        $rowsAffected = 0;
        foreach ($this->_getReferenceMapNormalized() as $map) {
            if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_UPDATE])) {
                switch ($map[self::ON_UPDATE]) {
                    case self::CASCADE:
                        $newRefs = array();
                        $where = array();
                        for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
                            $col = $this->_db->foldCase($map[self::COLUMNS][$i]);
                            $refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]);
                            if (array_key_exists($refCol, $newPrimaryKey)) {
                                $newRefs[$col] = $newPrimaryKey[$refCol];
                            }
                            $type = $this->_metadata[$col]['DATA_TYPE'];
                            $where[] = $this->_db->quoteInto(
                                $this->_db->quoteIdentifier($col, true) . ' = ?',
                                $oldPrimaryKey[$refCol], $type);
                        }
                        $rowsAffected += $this->update($newRefs, $where);
                        break;
                    default:
                        // no action
                        break;
                }
            }
        }
        return $rowsAffected;
    }
233438
private function templateStatementList(ParentNode $node) {
    while ($this->current) {
      if ($this->currentType === T_OPEN_TAG) {
        return;
      }
      elseif ($this->currentType === T_INLINE_HTML) {
        $node->addChild($this->mustMatchToken(T_INLINE_HTML));
      }
      elseif ($this->currentType === T_OPEN_TAG_WITH_ECHO) {
        $node->addChild($this->echoTagStatement());
      }
      else {
        throw new ParserException(
          $this->filename,
          $this->iterator->getLineNumber(),
          $this->iterator->getColumnNumber(),
          'expected PHP opening tag, but got ' . $this->iterator->current()->getText());
      }
    }
  }
1168113
public function export($item, array $extraAttributes = []): array
    {
        /** @var Site $item */
        $attributeObj = [];
        $extraAttributes = array_merge($extraAttributes, $this->additionalAttributes(\get_class($item)));
        foreach($extraAttributes as $attribute) {
            if ($attribute === 'propagateEntries') {
                $attributeObj[$attribute] = (bool) $item->$attribute;
            } else {
                $attributeObj[$attribute] = $item->$attribute;
            }
        }

        $siteObj = array_merge([
            'groupId' => $item->getGroup()->id,
            'group' => $item->getGroup()->name,
            'name' => $item->name,
            'handle' => $item->handle,
            'language' => $item->language,
            'primary' => $item->primary,
            'hasUrls' => (bool) $item->hasUrls,
            'baseUrl' => $item->baseUrl,
        ], $attributeObj);

        return $this->stripNulls($siteObj);
    }
463816
public static function getAutoHandledOrphans($flatten = true, $stripPrefix = 1)
    {
        $orphans = static::getOrphans();

        foreach ($orphans as $key => $value) {
            $value = explode('.', $key);

            $value = array_map('ucfirst', $value);

            foreach (range(1, $stripPrefix) as $i) {
                array_shift($value);
            }

            $value = implode(' ', $value);

            $orphans[$key] = $value;
        }

        if (!$flatten) {
            $reg = new Structure();

            foreach ($orphans as $key => $value) {
                $reg->set($key, $value);
            }

            $orphans = $reg->toArray();
        }

        return $orphans;
    }
1060541
protected function parseSelect($schema, $extras)
    {
        $fields = array_get($extras, ApiOptions::FIELDS);
        if (empty($fields)) {
            // minimally return id fields
            $idFields = array_get($extras, ApiOptions::ID_FIELD);
            if (empty($idFields)) {
                $idFields = $schema->primaryKey;
            }
            $fields = $idFields;
        }
        $fields = static::fieldsToArray($fields);
        $outArray = [];
        if (empty($fields)) {
            foreach ($schema->getColumns() as $fieldInfo) {
                if ($fieldInfo->isAggregate) {
                    continue;
                }
                $out = $this->parseFieldForSelect($fieldInfo);
                if (is_array($out)) {
                    $outArray = array_merge($outArray, $out);
                } else {
                    $outArray[] = $out;
                }
            }
        } else {
            $related = array_get($extras, ApiOptions::RELATED);
            $related = static::fieldsToArray($related);
            if (!empty($related) || $schema->fetchRequiresRelations) {
                // add any required relationship mapping fields
                foreach ($schema->getRelations() as $relation) {
                    if ($relation->alwaysFetch || in_array($relation->getName(true), $related)) {
                        foreach ($relation->field as $relField) {
                            if ($fieldInfo = $schema->getColumn($relField)) {
                                $relationField = $fieldInfo->getName(true); // account for aliasing
                                if (false === array_search($relationField, $fields)) {
                                    $fields[] = $relationField;
                                }
                            }
                        }
                    }
                }
            }
            foreach ($fields as $field) {
                if ($fieldInfo = $schema->getColumn($field, true)) {
                    $out = $this->parseFieldForSelect($fieldInfo);
                    if (is_array($out)) {
                        $outArray = array_merge($outArray, $out);
                    } else {
                        $outArray[] = $out;
                    }
                } else {
                    throw new BadRequestException('Invalid field requested: ' . $field);
                }
            }
        }

        return $outArray;
    }
229989
function appendLineParagraph( $element, $newParent )
    {
        eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext', $newParent, 'eZSimplifiedXMLInputParser::appendLineParagraph new parent' );
        $ret = array();
        $parent = $element->parentNode;
        if ( !$parent instanceof DOMElement )
        {
            return $ret;
        }

        $parentName = $parent->nodeName;
        $newParentName = $newParent != null ? $newParent->nodeName : '';

        // Correct structure by adding <line> and <paragraph> tags.
        if ( $parentName == 'line' || $this->XMLSchema->isInline( $parent ) )
        {
            return $ret;
        }

        if ( $newParentName == 'line' )
        {
            $element = $parent->removeChild( $element );
            $newParent->appendChild( $element );
            $newLine = $newParent;
            $ret['result'] = $newParent;
        }
        else if (
            $parentName === 'header'
            && (
                $parent->getElementsByTagName( 'line' )->length
                || $parent->getElementsByTagName( 'br' )->length
            )
        )
        {
            // by default the header element does not need a line element
            // unless it contains a <br> or a previously created <line>
            $newLine = $this->createAndPublishElement( 'line', $ret );
            $element = $parent->replaceChild( $newLine, $element );
            $newLine->appendChild( $element );
            $ret['result'] = $newLine;
        }
        elseif ( $parentName == 'paragraph' )
        {
            $newLine = $this->createAndPublishElement( 'line', $ret );
            $element = $parent->replaceChild( $newLine, $element );
            $newLine->appendChild( $element );
            $ret['result'] = $newLine;
        }
        elseif ( $newParentName == 'paragraph' )
        {
            $newLine = $this->createAndPublishElement( 'line', $ret );
            $element = $parent->removeChild( $element );
            $newParent->appendChild( $newLine );
            $newLine->appendChild( $element );
            $ret['result'] = $newLine;
        }
        elseif ( $this->XMLSchema->check( $parent, 'paragraph' ) )
        {
            $newLine = $this->createAndPublishElement( 'line', $ret );
            $newPara = $this->createAndPublishElement( 'paragraph', $ret );
            $element = $parent->replaceChild( $newPara, $element );
            $newPara->appendChild( $newLine );
            $newLine->appendChild( $element );
            $ret['result'] = $newLine;
        }

        return $ret;
    }
1006010
protected function getHeaders(\MUtil_Model_ModelAbstract $model, array $currentNames)
    {
        $lastParent = null;
        $results    = array();
        foreach ($currentNames as $name) {
            if ($model->is($name, 'type', \MUtil_Model::TYPE_NOVALUE)) {
                $results[$name] = $name;

            } elseif ($parent = $model->get($name, 'parent_question')) {
                // Insert parent header on name if it was not shown before
                $results[$parent] = $parent;
            }
        }

        return $results;
    }
275569
public function appendTo( $sourceNode, $newParentNode )
    {
        $mapper = $this->getMapper();

        return $mapper->moveNode( $sourceNode,
                                  $mapper::MOVE_APPEND,
                                  $newParentNode );
    }
194556
private function parseComplexDollarTemplateStringExpression($parentNode) {
        $var = $this->parseSimpleVariable($parentNode);
        $token = $this->getCurrentToken();
        if ($token->kind === TokenKind::OpenBracketToken) {
            return $this->parseTemplateStringSubscriptExpression($var);
        }
        return $var;
    }
770981
public function parentKeysToErrorName($parent_keys) {
		$result = [];
		if (!is_array($parent_keys)) {
			$parent_keys = [$parent_keys];
		}
		foreach ($parent_keys as $v) {
			if (empty($result)) {
				$result[] = $v;
			} else {
				$result[] = '[' . $v . ']';
			}
		}
		return implode('', $result);
	}
1308139
protected function insertTranslations(Model $mainModel, array $translations, array $insertedParentPKs)
    {
        if (!$translations) {
            return;
        }

        // The IDs of the model weren't known when preparing the bulk insert,
        // so we'll set the values of the foreign key now.
        $foreignKeyName = $mainModel->getRelationKey();

        $idKey = 0;

        foreach ($translations as &$translationsOfOneModel) {
            foreach ($translationsOfOneModel as &$translation) {
                $translation[$foreignKeyName] = $insertedParentPKs[$idKey];
            }

            $idKey++;
        }
        unset($translationsOfOneModel, $translation);

        // We'll flatten the records since they're grouped by model.
        $translations = Arr::flatten($translations, 1);

        foreach (array_chunk($translations, 500) as $chunk) {
            call_user_func([$mainModel->getTranslationModelName(), 'insert'], $chunk);
        }
    }
1105241
def _closure_parent_pk(self):
        """"""
        if hasattr(self, "%s_id" % self._closure_parent_attr):
            return getattr(self, "%s_id" % self._closure_parent_attr)
        else:
            parent = getattr(self, self._closure_parent_attr)
            return parent.pk if parent else None
864587
public function getRecursivePageChildIds($parentId)
    {
        $select = new Kwf_Model_Select();
        $ret = $this->_getChildPageIds($parentId);
        foreach ($ret as $i) {
            $ret = array_merge($ret, $this->getRecursivePageChildIds($i));
        }
        return $ret;
    }
821484
public function export($item, array $extraAttributes = []): array
    {
        /** @var AssetTransform $item */
        $attributeObj = [];
        $extraAttributes = array_merge($extraAttributes, $this->additionalAttributes(\get_class($item)));
        foreach($extraAttributes as $attribute) {
            $attributeObj[$attribute] = $item->$attribute;
        }

        $transformObj = array_merge([
            'name' => $item->name,
            'handle' => $item->handle,
            'mode' => $item->mode,
            'position' => $item->position,
            'width' => (int) $item->width,
            'height' => (int) $item->height,
            'quality' => (int) $item->quality,
            'interlace' => $item->interlace,
            'format' => $item->format,
        ], $attributeObj);

        return $this->stripNulls($transformObj);
    }
905131
public function select ($current_rule = [], $label_list = [], $multiple = false) {
		return array_merge([
			'null_skip'	=> true,
			['require', 'raise_exception' => true],
			['key', $label_list, 'is_array' => $multiple, 'raise_exception' => true],
		], $multiple ? $this->adjustOption($current_rule, 'is_array', $multiple) : $current_rule);
	}