/** * Processes a DataContainer object with a DataPointWorker * * @param DataContainer $dataContainer * @param AbstractDataPointWorker $dataPointWorker * @return string */ public function processWithWorker(AbstractDataPointWorker $dataPointWorker, DataContainer $dataContainer) { $dataPoints = $dataPointWorker->generateDataPoints($dataContainer); $code = StringFormatterWorker::vsprintf2($dataPointWorker->getTemplateContents(), $dataPoints); $dataPointWorker->processCode($dataContainer, $code); return $code; }
/** * Generates a formatted message string * * * @param string $code Message code to use * @param array $params Optional params to insert into message text * @return string * @throws \InvalidArgumentException */ public static function generateMessage($code, $params = []) { $class = __CLASS__; if (!defined("{$class}::{$code}")) { throw new \InvalidArgumentException("{$code} is not a valid error code."); } return StringFormatterWorker::vsprintf2(constant("{$class}::{$code}"), $params); }
public function test_vsprint2_properlyFormatsStringWithMultipleArgsWithSimilarNames() { $string = "Test string with multiple values: %foo% %fooBar% %bar% %barBaz% %baz%"; $args = array('foo' => '_fooValue_', 'fooBar' => '_fooBarValue_', 'bar' => '_barValue_', 'barBaz' => '_barBazValue_', 'baz' => '_bazValue_'); $expected = "Test string with multiple values: _fooValue_ _fooBarValue_ _barValue_ _barBazValue_ _bazValue_"; $actual = Formatter::vsprintf2($string, $args); $this->assertEquals($expected, $actual); }
/** * Formats the class name for the mock class * * @param string $className Target class name * @param string $format Mock class name format string * @return string */ private function formatMockClassName($className, $format) { return StringFormatterWorker::vsprintf2($format, array('FileName' => $className)); }
/** * Gets the mandatory properties code for an array of PropertyData classes * in a particular visibility. * * @param array $properties * @return string */ private function getMandatoryPropsCode($properties) { $code = ''; $template = " '%Property%' => %DefaultValue%," . PHP_EOL; foreach ($properties as $property) { $args = array('Property' => $property->name, 'DefaultValue' => $this->generateDefaultValueString($property)); $code .= StringFormatterWorker::vsprintf2($template, $args); } return $code; }