protected function _process($path)
{
$original = $contents = $this->Stage->source($path);
// Serializes data from PHP data into PHP code.
// Basically a code style conformant version of var_export()
$export = function ($values) use(&$export) {
$vals = [];
if (!is_array($values)) {
return $vals;
}
foreach ($values as $key => $val) {
if (is_array($val)) {
$vals[] = "'{$key}' => [" . implode(", ", $export($val)) . "]";
} else {
$val = var_export($val, true);
if ($val === 'NULL') {
$val = 'null';
}
if (!is_numeric($key)) {
$vals[] = "'{$key}' => {$val}";
} else {
$vals[] = "{$val}";
}
}
}
return $vals;
};
// Process field property.
$processor = function ($matches) use($export) {
eval('$data = [' . $matches[2] . '];');
$out = [];
foreach ($data as $key => $fixture) {
$pieces = explode('.', $fixture);
$fixtureName = $pieces[count($pieces) - 1];
$fixtureName = Inflector::pluralize($fixtureName);
$pieces[count($pieces) - 1] = $fixtureName;
$out[] = implode('.', $pieces);
}
return $matches[1] . "\n\t\t" . implode(",\n\t\t", $export($out)) . "\n\t" . $matches[3];
};
$contents = preg_replace_callback('/(public \\$fixtures\\s+=\\s+(?:array\\(|\\[))(.*?)(\\);|\\];)/ms', $processor, $contents, -1, $count);
return $this->Stage->change($path, $original, $contents);
}