src/WPConfigTransformer.php
protected function parse_wp_config( $src ) {
		$configs             = array();
		$configs['constant'] = array();
		$configs['variable'] = array();

		// Strip comments.
		foreach ( token_get_all( $src ) as $token ) {
			if ( in_array( $token[0], array( T_COMMENT, T_DOC_COMMENT ), true ) ) {
				$src = str_replace( $token[1], '', $src );
			}
		}

		preg_match_all( '/(?<=^|;|<\?php\s|<\?\s)(\h*define\s*\(\s*[\'"](\w*?)[\'"]\s*)(,\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*)((?:,\s*(?:true|false)\s*)?\)\s*;)/ims', $src, $constants );
		preg_match_all( '/(?<=^|;|<\?php\s|<\?\s)(\h*\$(\w+)\s*=)(\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*;)/ims', $src, $variables );

		if ( ! empty( $constants[0] ) && ! empty( $constants[1] ) && ! empty( $constants[2] ) && ! empty( $constants[3] ) && ! empty( $constants[4] ) && ! empty( $constants[5] ) ) {
			foreach ( $constants[2] as $index => $name ) {
				$configs['constant'][ $name ] = array(
					'src'   => $constants[0][ $index ],
					'value' => $constants[4][ $index ],
					'parts' => array(
						$constants[1][ $index ],
						$constants[3][ $index ],
						$constants[5][ $index ],
					),
				);
			}
		}

		if ( ! empty( $variables[0] ) && ! empty( $variables[1] ) && ! empty( $variables[2] ) && ! empty( $variables[3] ) && ! empty( $variables[4] ) ) {
			// Remove duplicate(s), last definition wins.
			$variables[2] = array_reverse( array_unique( array_reverse( $variables[2], true ) ), true );
			foreach ( $variables[2] as $index => $name ) {
				$configs['variable'][ $name ] = array(
					'src'   => $variables[0][ $index ],
					'value' => $variables[4][ $index ],
					'parts' => array(
						$variables[1][ $index ],
						$variables[3][ $index ],
					),
				);
			}
		}

		return $configs;
	}
protected function parse_wp_config( $src ) {
		$configs             = array();
		$configs['constant'] = array();
		$configs['variable'] = array();

		// Strip comments.
		foreach ( token_get_all( $src ) as $token ) {
			if ( in_array( $token[0], array( T_COMMENT, T_DOC_COMMENT ), true ) ) {
				$src = str_replace( $token[1], '', $src );
			}
		}

		preg_match_all( '/(?<=^|;|<\?php\s|<\?\s)(\h*define\s*\(\s*[\'"](\w*?)[\'"]\s*)(,\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*)((?:,\s*(?:true|false)\s*)?\)\s*;)/ims', $src, $constants );
		preg_match_all( '/(?<=^|;|<\?php\s|<\?\s)(\h*\$(\w+)\s*=)(\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*;)/ims', $src, $variables );

		if ( ! empty( $constants[0] ) && ! empty( $constants[1] ) && ! empty( $constants[2] ) && ! empty( $constants[3] ) && ! empty( $constants[4] ) && ! empty( $constants[5] ) ) {
			foreach ( $constants[2] as $index => $name ) {
				$configs['constant'][ $name ] = array(
					'src'   => $constants[0][ $index ],
					'value' => $constants[4][ $index ],
					'parts' => array(
						$constants[1][ $index ],
						$constants[3][ $index ],
						$constants[5][ $index ],
					),
				);
			}
		}

		if ( ! empty( $variables[0] ) && ! empty( $variables[1] ) && ! empty( $variables[2] ) && ! empty( $variables[3] ) && ! empty( $variables[4] ) ) {
			// Remove duplicate(s), last definition wins.
			$variables[2] = array_reverse( array_unique( array_reverse( $variables[2], true ) ), true );
			foreach ( $variables[2] as $index => $name ) {
				$configs['variable'][ $name ] = array(
					'src'   => $variables[0][ $index ],
					'value' => $variables[4][ $index ],
					'parts' => array(
						$variables[1][ $index ],
						$variables[3][ $index ],
					),
				);
			}
		}

		return $configs;
	}
protected function parse_wp_config ( $ src ) { $ configs = array ( ) ; $ configs [ 'constant' ] = array ( ) ; $ configs [ 'variable' ] = array ( ) ; // Strip comments. foreach ( token_get_all ( $ src ) as $ token ) { if ( in_array ( $ token [ 0 ] , array ( T_COMMENT , T_DOC_COMMENT ) , true ) ) { $ src = str_replace ( $ token [ 1 ] , '' , $ src ) ; } } preg_match_all ( '/(?<=^|;|<\?php\s|<\?\s)(\h*define\s*\(\s*[\'"](\w*?)[\'"]\s*)(,\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*)((?:,\s*(?:true|false)\s*)?\)\s*;)/ims' , $ src , $ constants ) ; preg_match_all ( '/(?<=^|;|<\?php\s|<\?\s)(\h*\$(\w+)\s*=)(\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*;)/ims' , $ src , $ variables ) ; if ( ! empty ( $ constants [ 0 ] ) && ! empty ( $ constants [ 1 ] ) && ! empty ( $ constants [ 2 ] ) && ! empty ( $ constants [ 3 ] ) && ! empty ( $ constants [ 4 ] ) && ! empty ( $ constants [ 5 ] ) ) { foreach ( $ constants [ 2 ] as $ index => $ name ) { $ configs [ 'constant' ] [ $ name ] = array ( 'src' => $ constants [ 0 ] [ $ index ] , 'value' => $ constants [ 4 ] [ $ index ] , 'parts' => array ( $ constants [ 1 ] [ $ index ] , $ constants [ 3 ] [ $ index ] , $ constants [ 5 ] [ $ index ] , ) , ) ; } } if ( ! empty ( $ variables [ 0 ] ) && ! empty ( $ variables [ 1 ] ) && ! empty ( $ variables [ 2 ] ) && ! empty ( $ variables [ 3 ] ) && ! empty ( $ variables [ 4 ] ) ) { // Remove duplicate(s), last definition wins. $ variables [ 2 ] = array_reverse ( array_unique ( array_reverse ( $ variables [ 2 ] , true ) ) , true ) ; foreach ( $ variables [ 2 ] as $ index => $ name ) { $ configs [ 'variable' ] [ $ name ] = array ( 'src' => $ variables [ 0 ] [ $ index ] , 'value' => $ variables [ 4 ] [ $ index ] , 'parts' => array ( $ variables [ 1 ] [ $ index ] , $ variables [ 3 ] [ $ index ] , ) , ) ; } } return $ configs ; }
Parses the source of a wp-config.php file.

@param string $src Config file source.

@return array
Parses the source of a wp - config . php file .