计算数组差集,专用于用数字索引的二维数组比较
@param $source
@param $subSource
@param $idField
@return array
499400
public static function arrayDiff($source,$subSource,$idField)
    {
        $keys=array();
        foreach($subSource as $item){
            $keys[]=Convert::getFieldValue($item, $idField,true);
        }

        $returnValue=[];
        foreach($source as $item){
            $key=Convert::getFieldValue($item, $idField,true);
            if(!in_array($key,$keys)){
                $returnValue[]=$item;
            }
        }
        return $returnValue;
    }
720063
function mergeSubResource(attrNode, subResourceConfig, context) {
    // Merge options from sub-resource to parent (order is irrelevant here):
    Object.keys(subResourceConfig).forEach(optionName => {
        if (optionName === 'attributes') {
            if (!attrNode.attributes) attrNode.attributes = {};
        } else if (optionName === 'dataSources') {
            const newDataSources = Object.assign({}, subResourceConfig.dataSources);

            if (attrNode.dataSources) {
                Object.keys(attrNode.dataSources).forEach(dataSourceName => {
                    if (newDataSources[dataSourceName]) {
                        if (attrNode.dataSources[dataSourceName].inherit) {
                            if (attrNode.dataSources[dataSourceName].inherit === 'inherit') {
                                newDataSources[dataSourceName] = Object.assign(
                                    {},
                                    newDataSources[dataSourceName],
                                    attrNode.dataSources[dataSourceName]
                                );
                            } else if (attrNode.dataSources[dataSourceName].inherit === 'replace') {
                                newDataSources[dataSourceName] = attrNode.dataSources[dataSourceName];
                            }
                        } else {
                            throw new ImplementationError(
                                `Cannot overwrite DataSource "${dataSourceName}"` +
                                    ` in "${context.attrPath.join('.')}" (maybe use "inherit"?)`
                            );
                        }
                    } else {
                        newDataSources[dataSourceName] = attrNode.dataSources[dataSourceName];
                    }
                });
            }

            attrNode.dataSources = newDataSources;
        } else if (typeof subResourceConfig[optionName] === 'object') {
            attrNode[optionName] = cloneDeep(subResourceConfig[optionName]);
        } else if (!(optionName in attrNode)) {
            attrNode[optionName] = subResourceConfig[optionName];
        }
    });

    attrNode._origNodes = attrNode._origNodes || [];
    attrNode._origNodes.push(subResourceConfig);
}
961231
private function iterateSubSpec($subSpecs, $fieldIndex, $subfieldIndex = null)
    {
        $valid = true;
        foreach ($subSpecs as $_subSpec) {
            if (is_array($_subSpec)) { // chained subSpecs (OR)
                foreach ($_subSpec as $this->currentSubSpec) {
                    $this->setIndexStartEnd($fieldIndex, $subfieldIndex);
                    if ($valid = $this->checkSubSpec()) {
                        break; // at least one of them is true (OR)
                    }
                }
            } else {
                // repeated SubSpecs (AND)
                $this->currentSubSpec = $_subSpec;
                $this->setIndexStartEnd($fieldIndex, $subfieldIndex);
                if (!$valid = $this->checkSubSpec()) {
                    break; // all of them have to be true (AND)
                }
            }
        }

        return $valid;
    }
488943
public static function map($source_dir, $subdir = true)
    {
        if (true == ($fp = opendir($source_dir))) {
            $source_dir = rtrim($source_dir, '/') . '/';
            $filedata   = array();

            while (false !== ($file = readdir($fp))) {
                if ($file == '.' or $file == '..') {
                    continue;
                }

                if ($subdir && is_dir($source_dir . $file)) {
                    $temp_array      = array();
                    $temp_array      = self::map($source_dir . $file . '/', $subdir);
                    $filedata[$file] = $temp_array;
                } else {
                    $filedata[] = $file;
                }
            }

            closedir($fp);
            return $filedata;
        } else {
            return false;
        }
    }
335072
protected function getRowId(array $row, $idField)
    {
        if (!array_key_exists($idField, $row)) {
            throw new ReaderException(
                sprintf(
                    'Row: "%s" has no field named "%s"',
                    $this->key(),
                    $idField
                )
            );
        }

        return $row[$idField];
    }
82055
protected function getDataStream($dataSource, $dataSourceOptions = null)
    {
        $dataSourceOptions = array_merge([
            'schema' => $this->schema(),
            'dialect' => isset($this->descriptor()->dialect) ? $this->descriptor()->dialect : null,
        ], (array) $dataSourceOptions);

        return new TabularDataStream($this->normalizeDataSource($dataSource, $this->basePath), $dataSourceOptions);
    }
440531
public function getSubdescriptor($context = null)
    {
        $sub = [];
        foreach ($this->subdescriptorFields as $fieldName => $fieldOptions) {
            if (is_numeric($fieldName)) {
                $fieldName = $fieldOptions;
                $fieldOptions = [];
            }
            $value = $this->getFieldValue($fieldName, $fieldOptions, $context);
            if (!empty($value)) {
                $sub[] = $value;
            }
        }

        return $sub;
    }
1285079
private function getAmountFields(Source $source, array $entry)
    {
        $fields = array();
        if (!empty($entry['totalvalue']) && !empty($entry['totalvalueexclvat'])) {
            // Get Acumulus amounts.
            $amountExAcumulus = $entry['totalvalueexclvat'];
            $amountIncAcumulus = $entry['totalvalue'];
            $amountVatAcumulus = $amountIncAcumulus - $amountExAcumulus;

            // Get local amounts.
            $localTotals = $source->getTotals();

            // Compare.
            $amountExStatus = $this->getAmountStatus($amountExAcumulus, $localTotals[Meta::InvoiceAmount]);
            $amountIncStatus = $this->getAmountStatus($amountIncAcumulus, $localTotals[Meta::InvoiceAmountInc]);
            $amountVatStatus = $this->getAmountStatus($amountVatAcumulus, $localTotals[Meta::InvoiceVatAmount]);

            $amountEx = $this->getFormattedAmount($amountExAcumulus, $amountExStatus);
            $amountInc = $this->getFormattedAmount($amountIncAcumulus, $amountIncStatus);
            $amountVat = $this->getFormattedAmount($amountVatAcumulus, $amountVatStatus);

            $fields['invoice_amount'] = array(
                'type' => 'markup',
                'label' => $this->t('invoice_amount'),
                'value' => sprintf('<div class="acumulus-amount">%1$s%2$s %4$s%3$s</div>', $amountEx, $amountVat, $amountInc, $this->t('vat')),
            );
        }
        return $fields;
    }
413909
public function removeSubfield (\HAB\Pica\Record\Subfield $subfield) 
    {
        $index = array_search($subfield, $this->_subfields, true);
        if ($index === false) {
            throw new InvalidArgumentException("Cannot remove subfield: Subfield not part of the subfield list");
        }
        unset($this->_subfields[$index]);
    }
1294882
public function getFields($blnIncludeMultiFields = false)
    {
        $objFields = new Collection();

        foreach ($this->__elements as $objPage) {
            if ($objPage->hasFields()) {
                foreach ($objPage->getFields() as $objFieldset) {
                    if ($objFieldset->hasFields()) {
                        foreach ($objFieldset->getFields() as $objField) {
                            if (is_object($objField)) {
                                if ($objField->hasFields()) {
                                    // Also add the multifield to the resulting collection, if $blnIncludeMultiFields is true.
                                    if (get_class($objField) == "ValidFormBuilder\\MultiField" && $blnIncludeMultiFields) {
                                        $objFields->addObject($objField);
                                    }

                                    foreach ($objField->getFields() as $objSubField) {
                                        if (is_object($objSubField)) {
                                            if ($objSubField->hasFields()) {
                                                // Also add the multifield to the resulting collection, if $blnIncludeMultiFields is true.
                                                if (get_class($objField) == "ValidFormBuilder\\MultiField" && $blnIncludeMultiFields) {
                                                    $objFields->addObject($objField);
                                                }

                                                foreach ($objSubField->getFields() as $objSubSubField) {
                                                    if (is_object($objSubSubField)) {
                                                        $objFields->addObject($objSubSubField);
                                                    }
                                                }
                                            } else {
                                                $objFields->addObject($objSubField);
                                            }
                                        }
                                    }
                                } else {
                                    $objFields->addObject($objField);
                                }
                            }
                        }
                    } else {
                        $objFields->addObject($objFieldset);
                    }
                }
            } else {
                $objFields->addObject($objPage);
            }
        }

        return $objFields;
    }
119542
public function findSources(string $fieldType, array $attributes, string $indexFrom, string $indexTo): array
    {
        foreach ($attributes as $key => $attribute) {
            if ($key === 'source') {
                $attributes[$key] = $this->getSource($fieldType, $attribute, $indexFrom, $indexTo);
            } elseif ($key === 'sources') {
                $attributes[$key] = $this->getSources($fieldType, $attribute, $indexFrom, $indexTo);
            } elseif (is_array($attribute)) {
                $attributes[$key] = $this->findSources($fieldType, $attribute, $indexFrom, $indexTo);
            }
        }

        return $attributes;
    }
46499
public static function addTo( &$source, $key, $subKey, $value = null )
    {
        $_target = static::clean( static::get( $source, $key, array() ) );
        static::set( $_target, $subKey, $value );
        static::set( $source, $key, $_target );

        return $_target;
    }
543822
public function getSubscriberFields($subscriber, $offset = 0, $limit = 100)
	{
		$fields = [];
		foreach ($this->client->get("subscribers/{$subscriber}/fields?offset={$offset}&limit={$limit}") as $subscriber) {
			$fields[] = new Resources\SubscriberField($this, $subscriber);
		}
		return $fields;
	}
1175887
private function fetchFields($subClass)
    {
        $fields = [];
        foreach ($this->fields as $name => $field) {
            if ($field instanceof $subClass) {
                $fields[$name] = $field;
            }
        }

        return $fields;
    }
450578
public function parse( string $source_path )
    {
        if ( !is_file($source_path) ){
            return array();
        }

        // ソースファイルの読み込み
        $fp = fopen( $source_path, 'r' );
        if ( !$fp ) {
            throw new PhpSourceParserException( self::ERROR_FILENOTFOUND, "Source file not found:$source_path" );
        }
        $line_no = 1;
        $source = [];
        while ( !feof($fp) ) {
            $buffer = fgets( $fp, 4096 );
            $source[$line_no++] = $buffer;
        }
        fclose( $fp );

        // 解析
        $state = self::LEXSTATE_NORMAL;
        $const_string_escaping = FALSE;

        $tokens = array();
        $rows = count($source);
        for( $i=1; $i<$rows; $i++ ){
            $line = $source[$i];
            $cols = strlen($line);
            $in_buffer = array();
            for($j=0;$j<$cols;$j++){
                $c = $line[$j];
                array_push( $in_buffer, $c );
            }

            $done_buffer = array();
            $buffer = '';
            $tokens_line = array();
            while( NULL !== ($c = array_shift($in_buffer)) ){
                switch( $state ){
                case self::LEXSTATE_NORMAL:
                    {
                        // デリミタ要素ならトークン区切りと判断
                        $delimiter = (strpos(self::DELEMITER_ELEMENTS,$c) !== FALSE);
                        if ( $delimiter ){
                            if ( strlen($buffer) > 0 ){
                                $tokens_line[] = $this->getElement( $buffer, $state );
                            }
                            $buffer = '';
                        }
                        // コメント突入判定
                        $d = array_shift($in_buffer);
                        if ( $d && $c === '/' && $d === '*' ){
                            $state = self::LEXSTATE_BLOCK_COMMENT;
                            $buffer = '/*';
                            break;
                        }
                        if ( $d && $c === '/' && $d === '/' ){
                            $state = self::LEXSTATE_LINE_COMMENT;
                            $buffer = '//';
                            break;
                        }
                        array_unshift( $in_buffer, $d );
                        // 文字列定数判定
                        if ( $c === '"' ){
                            $state = self::LEXSTATE_CONST_STRING_DQ;
                            $buffer = '"';
                            break;
                        }
                        if ( $c === "'" ){
                            $state = self::LEXSTATE_CONST_STRING_SQ;
                            $buffer = "'";
                            break;
                        }
                        // バッファに１文字だけ追加
                        if ( $delimiter ){
                            $tokens_line[] = new PhpSourceElement( $c, PhpSourceElement::TYPE_DELIMITER, $state );
                            $buffer = '';
                            array_unshift( $done_buffer, $c );
                        }
                        else{
                            $buffer .= (string)$c;
                            array_unshift( $done_buffer, $c );
                        }
                    }
                    break;
                case self::LEXSTATE_BLOCK_COMMENT:
                    {
                        // コメント脱出判定
                        $d = array_shift($in_buffer);
                        if ( $d && $c === '*' && $d === '/' ){
                            $buffer .= $c . $d;
                            $state = self::LEXSTATE_NORMAL;
                            $tokens_line[] = new PhpSourceElement( $buffer, PhpSourceElement::TYPE_COMMENT, $state );
                            $buffer = '';
                            array_unshift( $done_buffer, $c );
                            array_unshift( $done_buffer, $d );
                            break;
                        }
                        array_unshift( $in_buffer, $d );
                        $buffer .= $c;
                        array_unshift( $done_buffer, $c );
                    }
                    break;
                case self::LEXSTATE_LINE_COMMENT:
                    {
                        // コメント脱出判定
                        $d = array_shift($in_buffer);
                        if ( !$d ){
                            $state = self::LEXSTATE_NORMAL;
                            if ( strlen($buffer) > 0 ){
                                $tokens_line[] = new PhpSourceElement( $buffer, PhpSourceElement::TYPE_COMMENT, $state );
                                $buffer = '';
                            }
                            break;
                        }
                        array_unshift( $in_buffer, $d );
                        $buffer .= $c;
                        array_unshift( $done_buffer, $c );
                    }
                    break;
                case self::LEXSTATE_CONST_STRING_DQ:
                    {
                        // エスケープ判定
                        if ( $c === '\\' ){
                            $const_string_escaping = $const_string_escaping ? FALSE : TRUE;
                        }
                        // 文字列定数脱出判定
                        if ( $c === '"' && !$const_string_escaping ){
                            $state = self::LEXSTATE_NORMAL;
                            $buffer .= $c;
                            $tokens_line[] = new PhpSourceElement( $buffer, PhpSourceElement::TYPE_CONST_STRING, $state );
                            $buffer = '';
                            break;
                        }
                        $buffer .= $c;
                        array_unshift( $done_buffer, $c );
                    }
                    break;
                case self::LEXSTATE_CONST_STRING_SQ:
                    {
                        // エスケープ判定
                        if ( $c === '\\' ){
                            $const_string_escaping = $const_string_escaping ? FALSE : TRUE;
                        }
                        // 文字列定数脱出判定
                        if ( $c === "'" && !$const_string_escaping ){
                            $state = self::LEXSTATE_NORMAL;
                            $buffer .= $c;
                            $tokens_line[] = new PhpSourceElement( $buffer, PhpSourceElement::TYPE_CONST_STRING, $state );
                            $buffer = '';
                            break;
                        }
                        $buffer .= $c;
                        array_unshift( $done_buffer, $c );
                    }
                    break;
                }
            }
            if ( strlen($buffer) > 0 ){
                switch ( $state ){
                case self::LEXSTATE_BLOCK_COMMENT:
                    {
                        $tokens_line[] = new PhpSourceElement( $buffer, PhpSourceElement::TYPE_COMMENT, $state );
                    }
                    break;
                default:
                    {
                        $tokens_line[] = $this->getElement( $buffer, $state );
                    }
                    break;
                }
            }
            $tokens[$i] = $tokens_line;
            // １行コメントならノーマル状態に戻す
            if ( $state === self::LEXSTATE_LINE_COMMENT ){
                $state = self::LEXSTATE_NORMAL;
            }
        }

        return $tokens;
    }
1255118
public function fieldType($content, $column, $subField = null)
    {
        if ($content instanceof Content) {
            $name = (string) $content->getContenttype();
        } elseif ($content instanceof LegacyContent) {
            $name = $content->contenttype['slug'];
        } elseif (is_string($content)) {
            $name = $content;
        } else {
            throw new \BadMethodCallException(sprintf('The first parameter passed to fieldtype() but be a Content object or string, %s given', gettype($content)));
        }

        return $this->metadataDriver->getFieldTypeFor($name, $column, $subField);
    }
754445
public static function doInsert(array $options=array(), $instance=null, $IDField=null) {
		self::prepareQuery($options, $instance, $IDField);
		return self::$instances[$instance]->insert($options);
	}