@param string $matrix
@param array  $mapping

@throws \InvalidArgumentException

@return array
486508
public static function parse($matrix, array $mapping)
    {
        $matrix = trim($matrix);
        $areas = [];

        $rows = preg_split("/\n/", $matrix);
        $rowCount = \count($rows);
        if (0 === $rowCount || 0 === \strlen($rows[0])) {
            throw new \InvalidArgumentException('Invalid template matrix, a matrix should contain at least one row');
        }

        $colCount = \strlen($rows[0]);

        foreach ($rows as $y => $row) {
            if (\strlen($row) !== $colCount && $y > 0) {
                throw new \InvalidArgumentException(sprintf('Invalid template matrix, inconsistent row length, row "%d" should have a length of "%d"', $y, $colCount));
            }

            $cells = str_split($row);
            foreach ($cells as $x => $symbol) {
                if (!\array_key_exists($symbol, $mapping)) {
                    throw new \InvalidArgumentException(sprintf('Invalid template matrix, no mapping found for symbol "%s"', $symbol));
                }
                if (!isset($areas[$symbol])) {
                    $areas[$symbol] = [
                        'x' => $x,
                        'y' => $y,
                        'width' => 1,
                        'height' => 1,
                    ];
                } else {
                    // @todo handle non adjacent cells
                    if (false) {
                        //throw new \InvalidArgumentException(sprintf('Invalid template matrix, non adjacent symbol found "%s" at row "%s", col "%s"', $symbol, $y, $x));
                    }
                    $areas[$symbol]['width'] = $x - $areas[$symbol]['x'] + 1;
                    $areas[$symbol]['height'] = $y - $areas[$symbol]['y'] + 1;
                }
            }
        }

        foreach ($areas as &$area) {
            $area['x'] = $area['x'] / $colCount * 100;
            $area['y'] = $area['y'] / $rowCount * 100;

            $area['width'] = $area['width'] / $colCount * 100;
            $area['height'] = $area['height'] / $rowCount * 100;

            $area['right'] = 100 - ($area['width'] + $area['x']);
            $area['bottom'] = 100 - ($area['height'] + $area['y']);
        }

        $containers = [];
        foreach ($areas as $symbol => $config) {
            $containers[$mapping[$symbol]] = $config;
        }

        return $containers;
    }
1132207
public function setAssociationMapping($associationMapping)
    {
        if (!\is_array($associationMapping)) {
            throw new \InvalidArgumentException('The association mapping must be an array');
        }

        $this->associationMapping = $associationMapping;

        if (isset($associationMapping['type'])) {
            $this->type = $this->type ?: $associationMapping['type'];
            $this->mappingType = $this->mappingType ?: $associationMapping['type'];
        } else {
            throw new \InvalidArgumentException('Unknown association mapping type');
        }
        $this->fieldName = $associationMapping['fieldName'];
    }
234213
protected function setMapping(array $mapping)
	{
		$builder = $this->getContainerBuilder();
		$presenterFactory = $builder->getByType(IPresenterFactory::class);
		if ($presenterFactory === NULL) {
			throw new \Nette\InvalidStateException('Cannot find Nette\Application\IPresenterFactory implementation.');
		}
		$builder->getDefinition($presenterFactory)->addSetup('setMapping', [$mapping]);
	}
158324
protected function parseMapping(array $mapping) {
        foreach ($mapping['properties'] as $i => $property) {
            $name = $property['name'];
            $type = $property['type'];

            if (!isset($property['column'     ])) $property['column'     ] = $name;
            if (!isset($property['column-type'])) $property['column-type'] = $type;     // TODO: bug, $type may be a custom type

            if (isset($property['primary']) && $property['primary']===true)
                $mapping['identity'] = &$property;

            if (isset($property['version']) && $property['version']===true)
                $mapping['version'] = &$property;

            $column = $property['column'];
            $mapping['columns'][$column] = &$property;

            if ($type=='bool' || $type=='boolean') {
                $mapping['getters']['is'.$name ] = &$property;
                $mapping['getters']['has'.$name] = &$property;
            }
            else {
                $mapping['getters']['get'.$name] = &$property;
            }
            $mapping['properties'][$name] = &$property;
            unset($mapping['properties'][$i], $property);
        };

        if (isset($mapping['relations'])) {
            foreach ($mapping['relations'] as $i => $property) {
                $name  = $property['name' ];
                $assoc = $property['assoc'];

                // any association using a mandatory or optional join table
                if ($assoc=='many-to-many' || isset($property['join-table'])) {
                    if (!isset($property['join-table']))                       throw new RuntimeException('Missing attribute "join-table"="{table_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['key']))
                        $property['key'] = $mapping['identity']['name'];
                    else if (!isset($mapping['properties'][$property['key']])) throw new RuntimeException('Illegal attribute "key"="'.$property['key'].'" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['ref-column']))                       throw new RuntimeException('Missing attribute "ref-column"="{'.$property['join-table'].'.column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['fk-ref-column']))                    throw new RuntimeException('Missing attribute "fk-ref-column"="{'.$property['join-table'].'.column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                }

                // one-to-one (using no optional join table)
                else if ($assoc == 'one-to-one') {
                    if (!isset($property['column'])) {
                        if (!isset($property['key']))
                            $property['key'] = $mapping['identity']['name'];
                        else if (!isset($mapping['properties'][$property['key']])) throw new RuntimeException('Illegal attribute "key"="'.$property['key'].'" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                        if (!isset($property['ref-column']))                       throw new RuntimeException('Missing attribute "ref-column"="{column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    }
                }

                // one-to-many (using no optional join table)
                else if ($assoc == 'one-to-many') {
                    if (!isset($property['key']))
                        $property['key'] = $mapping['identity']['name'];
                    else if (!isset($mapping['properties'][$property['key']])) throw new RuntimeException('Illegal attribute "key"="'.$property['key'].'" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                    if (!isset($property['ref-column']))                       throw new RuntimeException('Missing attribute "ref-column"="{column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                }

                // many-to-one (using no optional join table)
                else if ($assoc == 'many-to-one') {
                    if (!isset($property['column'])) throw new RuntimeException('Missing attribute "column"="{column_name}" in relation [name="'.$name.'"  assoc="'.$assoc.'"...] of entity class "'.$mapping['class'].'"');
                }
                else                                 throw new RuntimeException('Illegal attribute "assoc"="'.$assoc.'" in relation [name="'.$name.'"...] of entity class "'.$mapping['class'].'"');

                if (isset($property['column']))
                    $mapping['columns'][$property['column']] = &$property;
                $getter = 'get'.$name;
                $mapping['getters'][$getter] = &$property;
                $mapping['relations'][$name] = &$property;
                unset($mapping['relations'][$i], $property);
            };
        }
        else $mapping['relations'] = [];

        $mapping['columns'] = \array_change_key_case($mapping['columns'], CASE_LOWER);
        $mapping['getters'] = \array_change_key_case($mapping['getters'], CASE_LOWER);

        return $mapping;
    }
859773
private function buildMap(ServiceLocatorInterface $sl, array $array)
    {
        $map = new Map();
        foreach ($array as $format => $visitorName) {
            $visitor = $visitorName;
            if (is_string($visitorName)) {
                if ($sl->has($visitorName)) {
                    $visitor = $sl->get($visitorName);
                } elseif (class_exists($visitorName)) {
                    $visitor = new $visitorName();
                }
            }

            if ($visitor instanceof VisitorInterface) {
                $map->set($format, $visitor);
                continue;
            }

            throw new InvalidArgumentException(sprintf(
                'Invalid (de-)serialization visitor"%s" given, must be a service name, '
                    . 'class name or an instance implementing JMS\Serializer\VisitorInterface',
                is_object($visitorName)
                    ? get_class($visitorName)
                    : (is_string($visitorName) ? $visitorName : gettype($visitor))
            ));
        }

        return $map;
    }
1266715
protected function _validateAndCompleteFieldMapping(array &$mapping)
    {
        // Check mandatory fields
        if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
            throw MappingException::missingFieldName($this->name);
        }
        if ( ! isset($mapping['type'])) {
            // Default to string
            $mapping['type'] = 'string';
        }

        // Complete fieldName and columnName mapping
        if ( ! isset($mapping['columnName'])) {
            $mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName'], $this->name);
        }

        if ($mapping['columnName'][0] === '`') {
            $mapping['columnName']  = trim($mapping['columnName'], '`');
            $mapping['quoted']      = true;
        }

        $this->columnNames[$mapping['fieldName']] = $mapping['columnName'];
        if (isset($this->fieldNames[$mapping['columnName']]) || ($this->discriminatorColumn != null && $this->discriminatorColumn['name'] == $mapping['columnName'])) {
            throw MappingException::duplicateColumnName($this->name, $mapping['columnName']);
        }

        $this->fieldNames[$mapping['columnName']] = $mapping['fieldName'];

        // Complete id mapping
        if (isset($mapping['id']) && $mapping['id'] === true) {
            if ($this->versionField == $mapping['fieldName']) {
                throw MappingException::cannotVersionIdField($this->name, $mapping['fieldName']);
            }

            if ( ! in_array($mapping['fieldName'], $this->identifier)) {
                $this->identifier[] = $mapping['fieldName'];
            }
            // Check for composite key
            if ( ! $this->isIdentifierComposite && count($this->identifier) > 1) {
                $this->isIdentifierComposite = true;
            }
        }

        if (Type::hasType($mapping['type']) && Type::getType($mapping['type'])->canRequireSQLConversion()) {
            if (isset($mapping['id']) && $mapping['id'] === true) {
                 throw MappingException::sqlConversionNotAllowedForIdentifiers($this->name, $mapping['fieldName'], $mapping['type']);
            }

            $mapping['requireSQLConversion'] = true;
        }
    }
1324550
private static function parseMapping($mapping, $flags, &$i = 0, $references = array())
    {
        $output = array();
        $len = strlen($mapping);
        ++$i;

        // {foo: bar, bar:foo, ...}
        while ($i < $len) {
            switch ($mapping[$i]) {
                case ' ':
                case ',':
                    ++$i;
                    continue 2;
                case '}':
                    if (self::$objectForMap) {
                        return (object) $output;
                    }

                    return $output;
            }

            // key
            $isKeyQuoted = in_array($mapping[$i], array('"', "'"), true);
            $key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array(), true);

            if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
                break;
            }

            if (':' === $key) {
                @trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
            }

            if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags)) {
                $evaluatedKey = self::evaluateScalar($key, $flags, $references);

                if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey)) {
                    @trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Squire\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED);
                }
            }

            if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
                @trigger_error('Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
            }

            while ($i < $len) {
                if (':' === $mapping[$i] || ' ' === $mapping[$i]) {
                    ++$i;

                    continue;
                }

                $tag = self::parseTag($mapping, $i, $flags);
                $duplicate = false;
                switch ($mapping[$i]) {
                    case '[':
                        // nested sequence
                        $value = self::parseSequence($mapping, $flags, $i, $references);
                        // Spec: Keys MUST be unique; first one wins.
                        // Parser cannot abort this mapping earlier, since lines
                        // are processed sequentially.
                        if (isset($output[$key])) {
                            @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Squire\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
                            $duplicate = true;
                        }
                        break;
                    case '{':
                        // nested mapping
                        $value = self::parseMapping($mapping, $flags, $i, $references);
                        // Spec: Keys MUST be unique; first one wins.
                        // Parser cannot abort this mapping earlier, since lines
                        // are processed sequentially.
                        if (isset($output[$key])) {
                            @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Squire\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
                            $duplicate = true;
                        }
                        break;
                    default:
                        $value = self::parseScalar($mapping, $flags, array(',', '}'), $i, null === $tag, $references);
                        // Spec: Keys MUST be unique; first one wins.
                        // Parser cannot abort this mapping earlier, since lines
                        // are processed sequentially.
                        if (isset($output[$key])) {
                            @trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Squire\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
                            $duplicate = true;
                        }
                        --$i;
                }

                if (!$duplicate) {
                    if (null !== $tag) {
                        $output[$key] = new TaggedValue($tag, $value);
                    } else {
                        $output[$key] = $value;
                    }
                }
                ++$i;

                continue 2;
            }
        }

        throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping));
    }
172290
public static function transpose(Matrix $matrix)
    {
        $grid = call_user_func_array(
            'array_map',
            array_merge(
                [null],
                $matrix->toArray()
            )
        );

        return new Matrix($grid);
    }
1155605
public function mapCollection(\Iterator $collection, $expression = null, $context = null)
    {
        foreach ($collection as $key => $record) {
            if (!is_array($record)) {
                throw new InvalidRecordException('Record must be an array.');
            }

            yield $key => $expression !== null
                ? $this->mapMapping($record, $expression, $context, $key)
                : $record;
        }
    }
388893
private function setRootDefault($key, array $mapping)
    {
        if (!isset($mapping[$key]) || !is_array($mapping[$key])) {
            $mapping[$key] = [];
        }
        return $mapping;
    }
244954
private function checkMapNames(array $map): void
    {
        $names = array_keys($map);
        $bad_names = preg_grep(self::RE_NAME, $names, PREG_GREP_INVERT);
        if ($bad_names) {
            throw new \InvalidArgumentException(
                'Bad names: ' . join(', ', $bad_names)
            );
        }
    }
179002
protected function loadInstancesForSubclass(IObjectMapping $mapping, array $rows, array $objects): array
    {
        $subClass          = $mapping->getObjectType();
        $objectsOfSubClass = [];
        $rowsForSubClass   = [];

        foreach ($objects as $key => $object) {
            if ($object instanceof $subClass) {
                $objectsOfSubClass[$key] = $object;
                $rowsForSubClass[$key]   = $rows[$key];
            }
        }

        return [$objectsOfSubClass, $rowsForSubClass];
    }
440702
@Override
  protected void remapData(int[][] mapping) throws IOException {
    super.remapData(mapping);
    T1[][] originalFullValueList = fullValueList.clone();
    fullValueList = operations.createMatrix1(mapping.length);
    for (int i = 0; i < mapping.length; i++) {
      for (int j = 0; j < mapping[i].length; j++) {
        if (j == 0) {
          setValue(i, originalFullValueList[mapping[i][j]],
              originalFullValueList[mapping[i][j]].length, false);
        } else {
          setValue(i, originalFullValueList[mapping[i][j]],
              originalFullValueList[mapping[i][j]].length, true);
        }
      }
    }
    fullValueList = newFullValueList;
  }
905635
public static function loadRepeater($repeater, $itemId, $mapping)
    {
        if(have_rows($repeater, $itemId))
        {
            $data = [];
            $n = 0;

            while(have_rows($repeater, $itemId))
            {
                the_row();
                $data[$n] = [];

                foreach($mapping as $key => $value)
                {
                    $data[$n][$key] = get_sub_field($value);
                }

                $n++;
            }

            return $data;
        }

        return false;
    }
80190
protected function mapMapping(array $record, Mapping $mapping, $context = null, $key = null)
    {
        $mapped = $this->mapFragment($record, $mapping->toArray(), $context, $key);

        if ($mapping->isWrapped()) {
            // Unwrap.
            return $mapped[0];
        }

        return $mapped;
    }
568412
public function setDiscriminatorMap(array $map)
    {
        foreach ($map as $value => $className) {
            $this->discriminatorMap[$value] = $className;
            if ($this->name == $className) {
                $this->discriminatorValue = $value;
            } else {
                if (!class_exists($className)) {
                    throw MappingException::invalidClassInDiscriminatorMap($className, $this->name);
                }
                if (is_subclass_of($className, $this->name)) {
                    $this->subClassNames[] = $className;
                }
            }
        }
    }
991760
public function mapManyToMany(array $mapping)
    {
        $mapping['type'] = self::MANY_TO_MANY;
        $mapping = $this->_validateAndCompleteManyToManyMapping($mapping);
        $this->_storeAssociationMapping($mapping);
    }