/** * Inject dynamic metadata into QUOTE tags in given XML * * @param string $xml Original XML * @return string Modified XML */ public function inject_metadata($xml) { $post_url = $this->post_url; $profile_url = $this->profile_url; $user = $this->user; return \s9e\TextFormatter\Utils::replaceAttributes($xml, 'QUOTE', function ($attributes) use($post_url, $profile_url, $user) { if (isset($attributes['post_id'])) { $attributes['post_url'] = str_replace('{POST_ID}', $attributes['post_id'], $post_url); } if (isset($attributes['time'])) { $attributes['date'] = $user->format_date($attributes['time']); } if (isset($attributes['user_id'])) { $attributes['profile_url'] = str_replace('{USER_ID}', $attributes['user_id'], $profile_url); } return $attributes; }); }
/** * @testdox replaceAttributes() tests * @dataProvider getReplaceAttributesTests */ public function testReplaceAttributes($original, $expected, $tagName, $callback) { $this->assertSame($expected, Utils::replaceAttributes($original, $tagName, $callback)); }