Convert chapter to Garp_Util_Configuration and validate its keys.

@param array|Garp_Util_Configuration $chapterData
@return Garp_Util_Configuration
779652
protected function _getValidChapterData($chapterData) {
        $chapterData = $chapterData instanceof Garp_Util_Configuration ?
            $chapterData : new Garp_Util_Configuration($chapterData);
        $chapterData
            ->obligate('content')
            ->setDefault('type', '');
        return $chapterData;
    }
841512
protected function getChapter( \DOMNodeList $dom_list, $index, $chapter_title ) {

		if ( empty( $chapter_title ) ) {
			$chapter_title = 'unknown';
		}
		$chapter = new \DOMDocument( '1.0', 'UTF-8' );

		// create a new node element
		$root = $chapter->createElement( 'div' );
		$root->setAttribute( 'class', $chapter_title );

		$chapter->appendChild( $root );

		// Start at the beginning if no h1 tags are found.
		// In other words...bring in the whole document.
		( '__UNKNOWN__' === $chapter_title ) ? $i = 0 : $i = $index;

		do {
			$node = $chapter->importNode( $dom_list->item( $i ), true );
			$chapter->documentElement->appendChild( $node );
			$i++;

			// TODO
			// This is problematic
			// DOMNodeList can be made up of DOMElement(s)
			// *and* DOMText(s) which do not have the property ->tagName

		} while ( @$dom_list->item( $i )->tagName != $this->tag && $i < $dom_list->length ); // @codingStandardsIgnoreLine

		// h1 tag will not be needed in the body of the html
		$h1 = $chapter->getElementsByTagName( $this->tag )->item( 0 );

		// removeChild is quick to throw a fatal error
		if ( $h1 && $this->tag === $h1->nodeName && 'div' === $h1->parentNode->nodeName ) {
			$chapter->documentElement->removeChild( $h1 );
		}

		$result = $chapter->saveHTML( $chapter->documentElement );

		// appendChild brings over the namespace which is superfluous on every html element
		// the string below is from the xslt file
		// @see includes/modules/import/odf/xsl/odt2html.xsl
		$result = preg_replace( '/xmlns="http:\/\/www.w3.org\/1999\/xhtml"/', '', $result );

		return $result;
	}
185994
protected function createNewItem($itemData)
    {
        $item = array_flip($this->columns);

        foreach ($item as $key => $value) {
            if (isset($itemData[$key])) {
                $item[$key] = $itemData[$key];
            } else {
                $item[$key] = null;
            }
        }

        return $item;
    }
685080
protected function parseContent( \DomDocument $xml, $chapter_title ) {

		$element = $xml->documentElement;
		$node_list = $element->childNodes;
		$chapter_node = '';
		$index = 0;

		// loop through child siblings
		for ( $i = 0; $i < $node_list->length; $i++ ) {

			$chapter_node = $this->findTheNode( $node_list->item( $i ), $chapter_title );
			if ( ! empty( $chapter_node ) ) {
				// assumes h1 is going to be first child of parent 'html'
				$index = $i;
				break;
			}
		}

		if ( $chapter_node ) {
			$chapter_title = strtolower( preg_replace( '/\s+/', '-', $chapter_node->nodeValue ) );
		}

		// iterate through
		return $this->getChapter( $node_list, $index, $chapter_title );
	}
1108478
protected function addHyperlinks( \DOMDocument $chapter ) {
		$ln = $chapter->getElementsByTagName( 'a' );

		for ( $i = $ln->length; --$i >= 0; ) {  // If you're deleting elements from within a loop, you need to loop backwards
			$link = $ln->item( $i );
			if (
				$link->hasAttribute( 'name' ) &&
				in_array( $link->getAttribute( 'name' ), [ '_GoBack' ], true )
			) {
				// Delete hidden Shift+F5 editing bookmark
				$link->parentNode->removeChild( $link );
				continue;
			}
			if ( $link->hasAttribute( 'class' ) ) {
				$ln_id = $link->getAttribute( 'class' );
				if ( array_key_exists( $ln_id, $this->ln ) ) {
					// Add external hyperlink
					$link->setAttribute( 'href', $this->ln[ $ln_id ] );
				}
			}
		}

		return $chapter;
	}
114370
protected function convert_existing_data_to_values(\stdClass $data) : \stdClass {
        $data->lawfulbases = explode(',', $data->lawfulbases);
        if (!empty($data->sensitivedatareasons)) {
            $data->sensitivedatareasons = explode(',', $data->sensitivedatareasons);
        }

        // Convert the single properties into number and unit.
        $strlen = strlen($data->retentionperiod);
        $data->retentionperiodnumber = substr($data->retentionperiod, 1, $strlen - 2);
        $data->retentionperiodunit = substr($data->retentionperiod, $strlen - 1);
        unset($data->retentionperiod);

        return $data;
    }
970188
public static function trim(array $contentData)
    {
        $data = [];

        foreach ($contentData as $item) {
            $data[] = trim($item);
        }

        return $data;
    }
170925
protected function convertToResource($data)
    {
        return Item::make($this->client, $this->bib, $this->holding, $data->item_data->pid)
            ->init($data);
    }
108085
public function convertAdventurersLog(string $data): array
    {
        // Parse data into ActivityFeed object
        $feedItems = [];

        try {
            $feed = new SimpleXmlElement($data);
        } catch (Exception $exception) {
            throw new DataConversionException("Could not parse the activity feed as XML.");
        }

        $itemElements = @$feed->xpath("/rss/channel/item");

        if ($itemElements === false) {
            throw new DataConversionException("Could not obtain any feed items from feed.");
        }

        foreach ($itemElements as $itemElement) {
            $time = new DateTime($itemElement->pubDate);
            $title = trim((string)$itemElement->title);
            $description = trim((string)$itemElement->description);

            if (!$time || !$title || !$description) {
                throw new DataConversionException(sprintf(
                    "Could not parse one of the activity feed items. (time: %s, title: %s, description: %s)",
                    $time ? $time->format("j-n-Y") : "", $title, $description
                ));
            }

            $feedItems[] = new ActivityFeedItem($time, $title, $description);
        }

        // Parse real name
        $titleElements = @$feed->xpath("/rss/channel/title");

        if ($titleElements === false || !count($titleElements)) {
            throw new DataConversionException("Could not obtain player name element from feed.");
        }

        $title = (string)$titleElements[0];
        $name = trim(substr($title, strrpos($title, ":") + 1));

        return [
            self::KEY_ACTIVITY_FEED => new ActivityFeed($feedItems),
            self::KEY_REAL_NAME => $name
        ];
    }
1094252
public static function toFile($configFile, array $configData, $mode = 0600)
    {
        $fileData = sprintf('<?php return %s;', var_export($configData, true));
        FileIO::writeFile($configFile, $fileData, $mode);
    }
1193806
protected function validateSegment($data)
    {
        $delimiter = $this->delimiter;

        return $this->convertToArray($data, function ($str) use ($delimiter) {
            if ('' == $str) {
                return array();
            }
            if ($delimiter == $str[0]) {
                $str = substr($str, 1);
            }

            return explode($delimiter, $str);
        });
    }
1290905
public function getConfigurationRaw($configData, array $customAttributes=[])
    {

        $getConfig = new \SimpleXMLElement(
            "<get-configuration>".
                "{$configData}".
            "</get-configuration>"

        );

        foreach ($customAttributes as $attrName => $attrValue) {

            $getConfig->addAttribute($attrName, $attrValue);

        }

        return $this->netConf()->sendRPC($getConfig->asXML());

    }
1330874
public function parseGetConfigurationResponse( array $aResponseData )
    {
        $aConfigurationData = array();
        $iKey               = 1;
        $iMaxIterations     = 10000;

        while ( !empty( $aResponseData["pm_configuration_${iKey}_key"] ) and ( $iKey <= $iMaxIterations ) ) {
            $aConfigurationData[$aResponseData["pm_configuration_${iKey}_key"]] =
                isset( $aResponseData["pm_configuration_${iKey}_value"] )
                    ? trim( (string) $aResponseData["pm_configuration_${iKey}_value"] )
                    : '';
            $iKey++;
        }

        return $aConfigurationData;
    }
428509
protected function _create(array $data) {
        $this->_validateLoadable();
        $snippetModel = new Model_Snippet();
        try {
            $snippetID = $snippetModel->insert($data);
            $snippet = $snippetModel->fetchRow(
                $snippetModel->select()->where('id = ?', $snippetID)
            );
            return $snippet;
        } catch (Garp_Model_Validator_Exception $e) {
            Garp_Cli::errorOut($e->getMessage());
        }
    }
631664
public function savePermissionCategory(array $data = [])
    {
        $model = new PermissionCategory($this->db);
        $model->data($data);
        try{
            $res = $model->saveCategory();
            return $res;
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
    }
490672
protected function convertChangeData($changeData)
    {
        $type = $changeData['type'];

        if (!isset($this->typeMap[$type])) {
            return new Error(sprintf('Could not convert change type %s, it is unknown to the system', $type));
        }

        $changeClass = $this->typeMap[$type];
        $changeClassInstance = $this->objectManager->get($changeClass);
        $changeClassInstance->injectPersistenceManager($this->persistenceManager);

        $subjectContextPath = $changeData['subject'];
        $subject = $this->nodeService->getNodeFromContextPath($subjectContextPath);

        if ($subject instanceof Error) {
            return $subject;
        }

        $changeClassInstance->setSubject($subject);

        if (isset($changeData['reference']) && method_exists($changeClassInstance, 'setReference')) {
            $referenceContextPath = $changeData['reference'];
            $reference = $this->nodeService->getNodeFromContextPath($referenceContextPath);

            if ($reference instanceof Error) {
                return $reference;
            }

            $changeClassInstance->setReference($reference);
        }

        if (isset($changeData['payload'])) {
            foreach ($changeData['payload'] as $propertyName => $value) {
                if (!in_array($propertyName, $this->disallowedPayloadProperties)) {
                    $methodParameters = $this->reflectionService->getMethodParameters($changeClass, ObjectAccess::buildSetterMethodName($propertyName));
                    $methodParameter = current($methodParameters);
                    $targetType = $methodParameter['type'];

                    // Fixme: The type conversion runs depending on the target node property type inside Property::class
                    // This is why we are not allowed to modify the value in any way.
                    // Without this condition the object was parsed to a string leading to fatal errors when changing images
                    // in the UI.
                    if ($propertyName !== 'value' && $targetType !== Property::class) {
                        $value = $this->propertyMapper->convert($value, $targetType);
                    }

                    ObjectAccess::setProperty($changeClassInstance, $propertyName, $value);
                }
            }
        }

        return $changeClassInstance;
    }
708631
public function process_book_chapters($data) {
        // Convert chapter files.
        $this->fileman->filearea = 'chapter';
        $this->fileman->itemid   = $data['id'];
        $data['content'] = moodle1_converter::migrate_referenced_files($data['content'], $this->fileman);

        $this->write_xml('chapter', $data, array('/chapter/id'));
    }