Validates the given event name.

@param string $event Event name.

@return $this

@throws InvalidArgumentException Thrown if the event name is invalid.
765292
public function validateEvent($event)
    {
        if (!is_string($event)
            || strlen($event) > 1000
            || strlen($event) < 1
        ) {
            throw new InvalidArgumentException(
                'Event name must be a non empty string of at most 1,000 ' .
                'characters',
                400
            );
        }

        return $this;
    }
745575
protected function raiseEvent($event)
    {
        if (!isset($this->eventHandlers[$event])) {
            return null;
        }

        $args = func_get_args();
        $args = array_slice($args, 1);

        // Check if the last argument is a callback.
        $count = count($args);
        $callBack = false;

        if (($count > 0) && is_object($args[$count - 1]) && is_callable($args[$count - 1])) {
            $callBack = $args[$count - 1];
            $args = array_slice($args, 0, -1);
        }

        $result = null;

        foreach ($this->eventHandlers[$event] as $delegate) {
            $answer = call_user_func_array($delegate, $args);

            if ($callBack !== false && $answer !== null) {
                call_user_func($callBack, $answer);
            }

            // If we don't have a result yet - make this the result. This way the first event handler to
            // return a non null result will be the overall result of the event.
            if ($result === null) {
                $result = $answer;
            }
        }

        return $result;
    }
628337
public function initialize(Event $event) {
		$table = $event->getSubject();
		if (!in_array(get_class($table), $this->config['tableClass'])) {
			return;
		}

		$this->_setValidators($table);
	}
320982
public function triggerEvent($event, $args = [])
    {
        if (!is_string($event) && !$event instanceof Event) {
            throw new \InvalidArgumentException(sprintf(
                '%s::%s only allow Event object or string.',
                get_called_class(),
                __FUNCTION__
            ));
        }

        if (!($event instanceof Event)) {
            if (isset($this->events[$event])) {
                $event = $this->events[$event];
            } else {
                $event = new Event($event);
            }
        }

        $event->mergeArguments($args);

        $listeners = [];

        if (isset($this->listeners[$event->getName()])) {
            foreach ($this->listeners[$event->getName()] as $listener) {
                if ($event->isStopped()) {
                    return $event;
                }

                if (!is_callable($listener)) {
                    $listener = [$listener, $event->getName()];
                }

                if (!is_callable($listener)) {
                    continue;
                }

                $listener($event);

                if ($this->debug) {
                    $listeners[] = $listener;
                }
            }
        }

        if ($this->debug) {
            $executedListeners = [];

            foreach ($listeners as $listener) {
                if ($listener instanceof \Closure) {
                    $ref = new \ReflectionFunction($listener);

                    $listener = ['{Closure}: ' . $ref->getFileName() . ' - Line: ' . $ref->getStartLine()];
                }

                if (is_object($listener[0])) {
                    $listener[0] = get_class($listener[0]);
                }

                $executedListeners[] = $listener;
            }

            $this->collector[] = [
                'event' => $event->getName(),
                'listeners' => $executedListeners,
            ];
        }

        return $event;
    }
344855
public function registerEventHandler($event, callable $handler)
    {
        if (empty($event)) {
            throw new InvalidArgumentException('Event name is required');
        }

        if (is_callable($handler)) {
            if (empty($this->event_handlers[$event])) {
                $this->event_handlers[$event] = [];
            }

            $this->event_handlers[$event][] = $handler;
        } else {
            throw new InvalidArgumentException('Handler not callable');
        }
    }
972054
public function addListener( $event, EventListener $listener ) {

		if ( !is_string( $event ) ) {
			throw new InvalidArgumentException( "Expected a string" );
		}

		$event = strtolower( $event );

		if ( !isset( $this->dispatchableListeners[$event] ) ) {
			$this->dispatchableListeners[$event] = array();
		}

		$this->dispatchableListeners[$event][] = $listener;
	}
791138
protected function validateMethod($method)
    {
        if ($method === null) {
            return $method;
        }

        if (!is_string($method)) {
            throw new \InvalidArgumentException('Method should be a string.');
        }

        $method = strtoupper($method);

        if (!in_array($method, $this->allowMethods)) {
            throw new \InvalidArgumentException('Invalid HTTP method: ' . $method);
        }

        return $method;
    }
450970
function setName($name)
    {
        if ($this->name !== null)
            throw new \Exception(sprintf(
                "Event with name (%s) are immutable. can`t set name (%s)."
                , $this->name, \Poirot\Std\flatten($name)
            ));

        $this->name = (string) $name;
        return $this;
    }
342466
public function validate(EventInterface $event)
    {
        $schema = $this->getEventSchema($event);
        if ($schema === null) {
            return new ValidationResult($this, $event, true);
        }

        $schemaValidator = $this->makeSchemaValidator($event, $schema);
        if ($schemaValidator->passes()) {
            return new ValidationResult($this, $event, true);
        } else {
            $errors = $schemaValidator->errors();
            return new ValidationResult($this, $event, false, $errors);
        }
    }
153202
public function raiseEvent(Event $event)
    {
        $name = $event->getName();
        if (isset($this->handlers[ $name ])) {
            ksort($this->handlers[ $name ]);
            $response = null;
            foreach ($this->handlers[ $name ] as $handlers) {
                foreach ($handlers as $handler) {
                    $response = $handler($event);
                }
            }
            $event->setResponse($response);
            $event->setHandled();
        }

        return $event;
    }
1278846
public function addEvent($event, $callable)
    {
        if (!is_callable($callable)) {
            throw new \InvalidArgumentException(
                sprintf(
                    '%s expects parameter 2 to be callable, %s given: %s',
                    __METHOD__,
                    gettype($callable),
                    print_r($callable, true)
                )
            );
        }

        if (!isset($this->events[$event])) {
            $this->events[$event] = array();
        }

        $this->events[$event][] = $callable;
    }
645613
public static function eventName($event)
    {
        static $constants = null;

        if (is_null($constants)) {
            $class = new \ReflectionClass('Resque\Event');

            $constants = array();
            foreach ($class->getConstants() as $name => $value) {
                $constants[$value] = strtolower($name);
            }
        }

        return isset($constants[$event]) ? $constants[$event] : false;
    }
1219598
private function validateName($name) {
        if (!is_string($name))    throw new IllegalTypeException('Illegal type of parameter $name: '.gettype($name));
        if ($name != trim($name)) throw new InvalidArgumentException('Invalid parameter $name: "'.$name.'" (enclosing white space)');

        if (strlen($name) && !preg_match('/^[^\s:]+(:[^\s:]+)*$/', $name))
            throw new InvalidArgumentException('Invalid parameter $name: "'.$name.'" (not a command name)');
        return $this;
    }
634033
public function fire($event)
    {
        $this->dispatch("$event.before");
        $this->dispatch($event);
        $this->dispatch("$event.after");

        return $this;
    }
450274
public function thenInvalid($message)
    {
        $this->thenPart = function ($v) use ($message) { throw new \InvalidArgumentException(sprintf($message, json_encode($v))); };

        return $this;
    }
704978
public function handleEvent(Event $event)
    {
        if (!$event instanceof UserInfoWithPassword) {
            throw new InvalidArgumentException(t('Invalid event type provided. Event type must be "UserInfoWithPassword".'));
        }

        // Track the password use
        $this->tracker->trackUse($event->getUserPassword(), $event->getUserInfoObject());
    }
92916
public function setEvent($event = [])
    {
        if (!empty($event['id'])) {
            $this->setLogs($event['id'], 'campaignEventId');
        }
        $overrides = [];
        if (!empty($event['config']['contactclient_overrides'])) {
            // Flatten overrides to key-value pairs.
            $jsonHelper = new JSONHelper();
            $array      = $jsonHelper->decodeArray($event['config']['contactclient_overrides'], 'Overrides');
            if ($array) {
                foreach ($array as $field) {
                    if (!empty($field->key) && !empty($field->value) && (empty($field->enabled) || true === $field->enabled)) {
                        $overrides[$field->key] = $field->value;
                    }
                }
            }
            if ($overrides) {
                $this->setOverrides($overrides);
            }
        }
        $this->event = $event;

        return $this;
    }