Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function startConversation(PersonInterface $sender, $recipient, $body, $subject = null)
 {
     if (!is_array($recipient) && !$recipient instanceof \Traversable) {
         $recipient = [$recipient];
     }
     Assert::allIsInstanceOf($recipient, 'FOS\\Message\\Model\\PersonInterface', '$recipient expected ether an instance or a collection of PersonInterface in Sender::startConversation().');
     Assert::string($body, '$body expected a string in Sender::startConversation(). Got: %s');
     Assert::nullOrString($subject, '$subject expected either a string or null in Sender::startConversation(). Got: %s');
     // Create conversation and message
     $conversation = $this->createAndPersistConversation($subject);
     $message = $this->createAndPersistMessage($conversation, $sender, $body);
     // Add the recipients links
     foreach ($recipient as $person) {
         $this->createAndPersistConversationPerson($conversation, $person);
         $this->createAndPersistMessagePerson($message, $person, false);
     }
     // Add the sender link
     $this->createAndPersistConversationPerson($conversation, $sender);
     $this->createAndPersistMessagePerson($message, $sender, true);
     // Flush the previously persisted entities
     $this->driver->flush();
     // Dispatch the event
     $this->dispatchConversationEvent($conversation, $message);
     return $conversation;
 }
Exemplo n.º 2
0
 /**
  * Creates a new version list.
  *
  * @param string         $path     The Puli path.
  * @param PuliResource[] $versions The versions of the resource, starting
  *                                 with the first.
  */
 public function __construct($path, array $versions)
 {
     Assert::stringNotEmpty($path, 'The Puli path must be a non-empty string. Got: %s');
     Assert::allIsInstanceOf($versions, 'Puli\\Repository\\Api\\Resource\\PuliResource');
     Assert::greaterThanEq(count($versions), 1, 'Expected at least one version.');
     $this->path = $path;
     $this->versions = array_values($versions);
 }
 /**
  * Construct.
  *
  * @param Filter[]  $filters    Filters.
  * @param Validator $validator  Alias validator.
  * @param string    $tableName  The table name.
  * @param string    $aliasField The alias field.
  * @param string    $separator  Value separator.
  */
 public function __construct($filters, Validator $validator, $tableName, $aliasField = 'alias', $separator = '-')
 {
     Assert::allIsInstanceOf($filters, 'Netzmacht\\Contao\\Toolkit\\Data\\Alias\\Filter');
     $this->validator = $validator;
     $this->aliasField = $aliasField;
     $this->tableName = $tableName;
     $this->separator = $separator;
     $this->filters = $filters;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  * 
  * @throws \LogicException
  */
 public function getCurrentPageWithForm(array $pages)
 {
     $routeParameters = $this->urlMatcher->match(parse_url($this->session->getCurrentUrl(), PHP_URL_PATH));
     Assert::allIsInstanceOf($pages, SymfonyPageInterface::class);
     foreach ($pages as $page) {
         if ($routeParameters['_route'] === $page->getRouteName()) {
             return $page;
         }
     }
     throw new \LogicException('Route name could not be matched to provided pages.');
 }
Exemplo n.º 5
0
 /**
  * Creates a new type.
  *
  * @param string             $name       The name of the type.
  * @param BindingParameter[] $parameters The parameters that can be set
  *                                       during binding.
  */
 public function __construct($name, array $parameters = array())
 {
     Assert::stringNotEmpty($name, 'The type name must be a non-empty string. Got: %s');
     Assert::startsWithLetter($name, 'The type name must start with a letter. Got: %s');
     Assert::allIsInstanceOf($parameters, 'Puli\\Discovery\\Api\\Binding\\BindingParameter');
     $this->name = $name;
     foreach ($parameters as $parameter) {
         $this->parameters[$parameter->getName()] = $parameter;
     }
     // Sort to facilitate comparison
     ksort($this->parameters);
 }
Exemplo n.º 6
0
 /**
  * Creates a new type.
  *
  * @param string             $name         The name of the type.
  * @param string             $bindingClass The class name of the accepted
  *                                         bindings.
  * @param BindingParameter[] $parameters   The parameters that can be set
  *                                         for a binding.
  */
 public function __construct($name, $bindingClass, array $parameters = array())
 {
     Assert::stringNotEmpty($name, 'The type name must be a non-empty string. Got: %s');
     Assert::allIsInstanceOf($parameters, 'Puli\\Discovery\\Api\\Type\\BindingParameter');
     if (!class_exists($bindingClass) && !interface_exists($bindingClass)) {
         throw new InvalidArgumentException(sprintf('The binding class "%s" is neither a class nor an ' . 'interface name. Is there a typo?', $bindingClass));
     }
     $this->name = $name;
     $this->acceptedBindingClass = $bindingClass;
     foreach ($parameters as $parameter) {
         $this->parameters[$parameter->getName()] = $parameter;
     }
     // Sort to facilitate comparison
     ksort($this->parameters);
 }
Exemplo n.º 7
0
 /**
  * Creates a new migration manager.
  *
  * @param JsonMigration[]    $migrations The migrations migrating a JSON
  *                                       object between individual versions
  * @param JsonVersioner|null $versioner  The versioner that should be used
  */
 public function __construct(array $migrations, JsonVersioner $versioner = null)
 {
     Assert::allIsInstanceOf($migrations, __NAMESPACE__ . '\\JsonMigration');
     $this->versioner = $versioner ?: new SchemaUriVersioner();
     foreach ($migrations as $migration) {
         $this->migrationsBySourceVersion[$migration->getSourceVersion()] = $migration;
         $this->migrationsByTargetVersion[$migration->getTargetVersion()] = $migration;
         $this->knownVersions[] = $migration->getSourceVersion();
         $this->knownVersions[] = $migration->getTargetVersion();
     }
     $this->knownVersions = array_unique($this->knownVersions);
     uksort($this->migrationsBySourceVersion, 'version_compare');
     uksort($this->migrationsByTargetVersion, 'version_compare');
     usort($this->knownVersions, 'version_compare');
 }
Exemplo n.º 8
0
 /**
  * @param string $summary
  * @param DocBlock\Description $description
  * @param DocBlock\Tag[] $tags
  * @param Types\Context $context The context in which the DocBlock occurs.
  * @param Location $location The location within the file that this DocBlock occurs in.
  * @param bool $isTemplateStart
  * @param bool $isTemplateEnd
  */
 public function __construct($summary = '', DocBlock\Description $description = null, array $tags = [], Types\Context $context = null, Location $location = null, $isTemplateStart = false, $isTemplateEnd = false)
 {
     Assert::string($summary);
     Assert::boolean($isTemplateStart);
     Assert::boolean($isTemplateEnd);
     Assert::allIsInstanceOf($tags, Tag::class);
     $this->summary = $summary;
     $this->description = $description ?: new DocBlock\Description('');
     foreach ($tags as $tag) {
         $this->addTag($tag);
     }
     $this->context = $context;
     $this->location = $location;
     $this->isTemplateEnd = $isTemplateEnd;
     $this->isTemplateStart = $isTemplateStart;
 }
 /**
  * @param \AppBundle\Entity\User[] $recipients
  */
 public function setRecipients($recipients)
 {
     \Webmozart\Assert\Assert::allIsInstanceOf($recipients, User::class);
     \Webmozart\Assert\Assert::notEmpty($recipients);
     $this->recipients = $recipients;
 }
 /**
  * @param PromotionEligibilityCheckerInterface[] $promotionEligibilityCheckers
  */
 public function __construct(array $promotionEligibilityCheckers)
 {
     Assert::notEmpty($promotionEligibilityCheckers);
     Assert::allIsInstanceOf($promotionEligibilityCheckers, PromotionEligibilityCheckerInterface::class);
     $this->promotionEligibilityCheckers = $promotionEligibilityCheckers;
 }
Exemplo n.º 11
0
 /**
  * @param OrderTaxesApplicatorInterface[] $applicators
  */
 private function assertApplicatorsHaveCorrectType(array $applicators)
 {
     Assert::allIsInstanceOf($applicators, OrderTaxesApplicatorInterface::class, 'Order taxes applicator should have type "%2$s". Got: %s');
 }
Exemplo n.º 12
0
 /**
  * Construct.
  *
  * @param ValueFormatter[]|array $filters List of filters.
  */
 public function __construct(array $filters)
 {
     Assert::allIsInstanceOf($filters, 'Netzmacht\\Contao\\Toolkit\\Dca\\Formatter\\Value\\ValueFormatter');
     $this->filters = $filters;
 }
 /**
  * {@inheritdoc}
  */
 public function merge($resources)
 {
     Assert::allIsInstanceOf($resources, 'Puli\\Repository\\Api\\Resource\\Resource');
     // only start merging after validating all resources
     foreach ($resources as $resource) {
         $this->resources[] = $resource;
     }
 }