/** * {@inheritDoc} */ public function process(ProcessableInterface $processable, array $variables) { $multi = '' !== $processable->getMatch('multi') ? $processable->getMatch('multi') : null; $property = !is_null($processable->getMatch('property')) ? $processable->getMatch('property') : null; if (strpos($processable->getMatch('reference'), '*')) { return $this->objects->random($processable->getMatch('reference'), $multi, $property); } if (null !== $multi) { throw new \UnexpectedValueException('To use multiple references you must use a mask like "' . $processable->getMatch('multi') . 'x @user*", otherwise you would always get only one item.'); } return $this->objects->find($processable->getMatch('reference'), $property); }
/** * {@inheritDoc} */ public function process(ProcessableInterface $processable, array $variables) { $multi = '' !== $processable->getMatch('multi') ? $processable->getMatch('multi') : null; $property = !is_null($processable->getMatch('property')) ? $processable->getMatch('property') : null; $sequence = !is_null($processable->getMatch('sequence')) ? $processable->getMatch('sequence') : null; if (strpos($reference = $processable->getMatch('reference'), '*')) { return $this->objects->random($reference, $multi, $property); } if ($sequence && ($reference = $processable->getMatch('reference'))) { $from = $processable->getMatch('from'); $to = $processable->getMatch('to'); $set = []; foreach (range($from, $to) as $id) { $set[] = $this->objects->get($reference . $id); } return $set; } if (null !== $multi) { throw new \UnexpectedValueException('To use multiple references you must use a mask like "' . $processable->getMatch('multi') . 'x @user*", otherwise you would always get only one item.'); } return $this->objects->find($processable->getMatch('reference'), $property); }
/** * hydrates each instance described by fixtures and returns the final non-local list * * @param array $fixtures * @return array */ protected function populateObjects(array $fixtures) { $objects = array(); foreach ($fixtures as $fixture) { $this->objects->set('self', $this->objects->get($fixture->getName())); $this->populator->populate($fixture); $this->objects->remove('self'); // add the object in the object store unless it's local if (!$fixture->isLocal()) { $objects[$fixture->getName()] = $this->getReference($fixture->getName()); } } return $objects; }
/** * populate all the properties for the object described by the given fixture * * @param Fixture $fixture */ public function populate(Fixture $fixture) { $class = $fixture->getClass(); $name = $fixture->getName(); $object = $this->objects->get($name); foreach ($fixture->getProperties() as $property) { $key = $property->getName(); $val = $property->getValue(); if (is_array($val) && '{' === key($val)) { throw new \RuntimeException('Misformatted string in object ' . $name . ', ' . $key . '\'s value should be quoted if you used yaml'); } $value = $property->requiresUnique() ? $this->generateUnique($fixture, $property) : $this->processor->process($property, $fixture->getSetProperties(), $fixture->getValueForCurrent()); foreach ($this->setters as $setter) { if ($setter->canSet($fixture, $object, $key, $value)) { $setter->set($fixture, $object, $key, $value); $fixture->setPropertyValue($key, $value); break; } } if (!array_key_exists($key, $fixture->getSetProperties())) { throw new \UnexpectedValueException('Could not determine how to assign ' . $key . ' to a ' . $class . ' object'); } } }