Creates a handler.

@param string $id     - Handler ID.
@param string $type   - Handler type.
@param int    $level  - Level.
@param array  $config - Handler config.

@throws InvalidConfigException

@return HandlerInterface
978792
public function createHandler(string $id, string $type, int $level, array $config): HandlerInterface
    {
        if (!isset($this->_handlers[$id])) {
            $config = array_replace(
                [
                    'processorIds'          => []
                ],
                $config
            );

            if (!is_array($config['processorIds'])) {
                throw InvalidConfigException::create('processorIds', 'array');
            }

            /** @var HandlerInterface $handler */
            $handler = null;

            switch ($type) {
                case self::HANDLER_TYPE_STREAM:
                    $config = array_replace(
                        [
                            'bubble'            => true,
                            'filePermission'    => null,
                            'useLocking'        => false
                        ],
                        $config
                    );

                    if (!isset($config['stream']) || !is_string($config['stream'])) {
                        throw InvalidConfigException::create('stream', 'string');
                    }

                    $handler = new StreamHandler(
                        $config['stream'],
                        $level,
                        $config['bubble'],
                        $config['filePermission'],
                        $config['useLocking']
                    );

                    $this->setHandler($id, $handler);

                    break;
                case self::HANDLER_TYPE_ERROR_LOG:
                    $config = array_replace(
                        [
                            'messageType'       => ErrorLogHandler::OPERATING_SYSTEM,
                            'bubble'            => true,
                            'expandNewLines'    => false
                        ],
                        $config
                    );
                    $handler = new ErrorLogHandler(
                        $config['messageType'],
                        $level,
                        $config['bubble'],
                        $config['expandNewLines']
                    );

                    $this->setHandler($id, $handler);

                    break;
                case self::HANDLER_TYPE_NULL:
                    $handler = new NullHandler($level);

                    $this->setHandler($id, $handler);

                    break;
                default:
                    throw new \InvalidArgumentException(
                        'Type "'.$type.'" is not handled yet by this component. You can set manually the handler '.
                        'instance using the "setHandler" method.'
                    );
            }

            if ($config['processorIds']) {
                foreach ($config['processorIds'] as $processorId) {
                    if (!isset($this->_processors[$processorId])) {
                        throw InvalidConfigException::create(
                            'processorIds',
                            'array',
                            'Additionally, processor ID "'.$processorId.'" does not exist.'
                        );
                    }

                    $handler->pushProcessor($this->_processors[$processorId]);
                }
            }

            $this->_handlers[$id] = $handler;
        }

        return $this->_handlers[$id];
    }
708522
public function stepCreateRecord($type, $id) {
		$class = $this->convertTypeToClass($type);
		$fields = $this->prepareFixture($class, $id);
		$this->fixtureFactory->createObject($class, $id, $fields);
	}
266242
private function _createRedisHandler(array $handlerConfig, $level)
    {
        if (false === array_key_exists('url', $handlerConfig)) {
            throw new MonologCreator\Exception(
                'url configuration for redis handler is missing'
            );
        }

        if (false === array_key_exists('key', $handlerConfig)) {
            throw new MonologCreator\Exception(
                'key configuration for redis handler is missing'
            );
        }

        return new Monolog\Handler\RedisHandler(
            $this->_createPredisClient($handlerConfig['url']),
            $handlerConfig['key'],
            $this->_levels[$level]
        );
    }
345107
public static function setHandler($level = null, $handler = null)
    {
        if (empty($level)) {
            $level = static::DEFAULT_LEVEL;
        }

        if (!empty($handler)) {
            static::$handler = $handler;
            return;
        }

        static::$handler = new \Monolog\Handler\StdoutHandler(constant("\Monolog\Logger::$level"));
        static::$handler->setFormatter(static::getFormatter());
    }
989069
protected function buildTemplateIdentifier($id, $type = self::TEMPLATE_IDENTIFIER_FORM)
    {
        $type = strtoupper($type);

        return self::TEMPLATE_BRACKETS_OPEN.
            self::TEMPLATE_PREFIX.
            $type.
            '-'.
            $id.
            self::TEMPLATE_BRACKETS_CLOSE;
    }
258682
public function setDebug($level, $type = 'session') {
		$level = (int)$level;

		if ($type === 'session') {
			if ($level < 0) {
				$this->request->getSession()->delete('Setup.debug');
				return false;
			}
			$this->request->getSession()->write('Setup.debug', $level);
			return true;
		}

		$cookieName = Configure::read('Session.cookie');
		if (empty($cookieName)) {
			$cookieName = 'CAKEPHP';
		}

		$id = null;
		if ($type === 'session') {
			$id = isset($_COOKIE[$cookieName]) ? $_COOKIE[$cookieName] : '';

		} elseif ($type === 'ip') {
			$ip = env('REMOTE_ADDR');
			$host = 'unknown';
			if (!empty($ip)) {
				$host = gethostbyaddr($ip);
			}
			$id = $ip . '-' . $host;
		}
		if ($id === null) {
			throw new Exception('Invalid type');
		}

		$file = TMP . 'debugOverride-' . $id . '.txt';
		if ($level < 0) {
			if (file_exists($file)) {
				unlink($file);
			}
			return false;
		}

		if (!empty($id)) {
			if (file_put_contents($file, $level)) {
				return (bool)$level;
			}
		}

		return false;
	}
1089961
function( index, type, config ) {
		var currentHandler,
			InputHandler = inputHandlerMap[ type ],
			controller = this.controllers.get( index );

		this.initInputHandlers( index );
		currentHandler = this.inputHandlers[ index ][ type ];
		if ( currentHandler ) {
			currentHandler.disable();
		}

		this.inputHandlers[ index ][ type ] = new InputHandler( controller, config );

		if ( this._enabled ) {
			this.inputHandlers[ index ][ type ].enable();
		}
	}
461463
protected function _create(array $data, $type, $id = null, array $parameters = []) {
        return $this->__create($data, $this->index(), $type, $id, $parameters);
    }
782409
public function setTypeHandler($type, TypeHandler $typeHandler) {
		if (!is_string($type) || empty($type))
			throw new \InvalidArgumentException("Type must be defined as a string");	
		$this->typeHandlers[$type] = $typeHandler;
	}
125689
protected function createMonologDriver(array $config)
    {
        if (!is_a($config['handler'], HandlerInterface::class, true)) {
            throw new InvalidArgumentException(
                $config['handler'] . ' must be an instance of ' . HandlerInterface::class
            );
        }

        return new Monolog(
            $this->parseChannel($config), [$this->prepareHandler(
                $this->app->make($config['handler'], $config['with'] ?? []), $config
            )]
        );
    }
1270008
protected function createHandler(ContainerBuilder $container, array $config, $definitionId)
    {
        // cURL handler
        $singleHandler   = (new Definition('GuzzleHttp\Ring\Client\CurlHandler'))
            ->setPublic(false);

        $this->setFactoryToDefinition('Elasticsearch\ClientBuilder', 'defaultHandler', $singleHandler);

        $singleHandlerId = $definitionId.'.single_handler';
        $container->setDefinition($singleHandlerId, $singleHandler);

        // Headers handler
        $headersHandler = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\HeadersHandler'))
            ->setPublic(false)
            ->setArguments([new Reference($singleHandlerId)]);
        if (isset($config['headers'])) {
            foreach ($config['headers'] as $key => $value) {
                $headersHandler->addMethodCall('setHeader', [$key, $value]);
            }
        }
        $headersHandlerId = $definitionId.'.headers_handler';
        $container->setDefinition($headersHandlerId, $headersHandler);

        // Event handler
        $eventHandler   = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\EventHandler'))
            ->setPublic(false)
            ->setArguments([new Reference('event_dispatcher'), new Reference($headersHandlerId)]);
        $eventHandlerId = $definitionId.'.event_handler';
        $container->setDefinition($eventHandlerId, $eventHandler);

        return $eventHandlerId;
    }
1360623
public function delete($_type = null, $id = null)
    {
        // setting up an event for the delete
        $_event = new Event('Controller.PostTypes.beforeDelete.' . $this->_type, $this, [
            'id' => $id,
        ]);
        $this->eventManager()->dispatch($_event);

        $postType = $this->Model->get($id);
        
        $this->request->allowMethod(['post', 'delete']);
        
        if ($this->Model->delete($postType)) {
            // setting up an event for the delete
            $_event = new Event('Controller.PostTypes.afterDelete.' . $this->_type, $this, [
                'id' => $id,
            ]);
            $this->eventManager()->dispatch($_event);
            
            $this->Flash->success(__('The {0} has been deleted.', [$this->Settings['type']]));
            
            return $this->redirect(['action' => 'index', 'type' => $this->_type]);
        } else {
            $this->Flash->error(__('The {0} could not be deleted. Please, try again.', [$this->Settings['type']]));
            return $this->redirect(['action' => 'index', 'type' => $this->_type]);
        }
    }
1204399
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        $this->eventDispatcher = $this->container['internal.event_dispatcher'];

        $controllerListener = new ControllerListener();
        $controllerListener->setContainer($this->container);
        $this->attach(KernelEvents::FILTER_CONTROLLER, [$controllerListener, 'filterController'], 255);

        foreach ($this->container['event_listeners'] as $config) {
            try {
                $class = $this->container[$config['class']];
            } catch (\Exception $exception) {
                $class = new $config['class']();
                if ($class instanceof ContainerAwareInterface) {
                    $class->setContainer($this->container);
                }
            }

            $this->attach($config['event'], [$class, $config['method']], $config['priority']);
        }

        return $this->app->handle($request, $type, $catch);
    }
518524
public function create($handlerType, $level)
    {
        if (false === array_key_exists('handler', $this->_config)) {
            throw new MonologCreator\Exception(
                'no handler configuration found'
            );
        }

        if (false === array_key_exists($handlerType, $this->_config['handler'])) {
            throw new MonologCreator\Exception(
                'no handler configuration found for handlerType: '
                . $handlerType
            );
        }

        $handler       = null;
        $handlerConfig = $this->_config['handler'][$handlerType];

        // evaluate handler
        if ('stream' === $handlerType) {
            $handler = $this->_createStreamhandler($handlerConfig, $level);
        } elseif ('udp' === $handlerType) {
            $handler = $this->_createUdphandler($handlerConfig, $level);
        } elseif ('redis' === $handlerType) {
            $handler = $this->_createRedisHandler($handlerConfig, $level);
        } else {
            throw new MonologCreator\Exception(
                'handler type: ' . $handlerType . ' is not supported'
            );
        }

        // set formatter
        if (true === array_key_exists('formatter', $handlerConfig)) {
            $handler->setFormatter(
                $this->_formatterFactory->create($handlerConfig['formatter'])
            );
        }

        return $handler;
    }
229838
public function viewBlockAction($type, $typeId, $id)
    {
        $this->getDoctrine()->getManager()->getFilters()->disable('draftversion');

        /** @var BlockManager $manager */
        $manager = $this->get('opifer.content.block_manager');

        /** @var Environment $environment */
        $environment = $this->get(sprintf('opifer.content.block_%s_environment', $type));
        $version = $manager->getNewVersion($id);

        $environment->load($typeId)->setVersion($version);

        $block = $environment->getBlock($id);

        $environment->setBlockMode('manage');

        $service = $manager->getService($block);

        $this->get('opifer.content.twig.content_extension')->setBlockEnvironment($environment);


        return new JsonResponse(['view' => $service->manage($block)->getContent()]);
    }
943719
public function buildQueryType(
        string $type,
        QueryTypeHandlerInterface $handler,
        array $config
    ): QueryTypeInterface {
        $parameterBuilder = $this->parameterBuilderFactory->createParameterBuilder();
        $handler->buildParameters($parameterBuilder);
        $parameterDefinitions = $parameterBuilder->buildParameterDefinitions();

        return QueryType::fromArray(
            [
                'type' => $type,
                'isEnabled' => $config['enabled'],
                'name' => $config['name'] ?? '',
                'handler' => $handler,
                'parameterDefinitions' => $parameterDefinitions,
            ]
        );
    }
1290649
public function sendUserMessage($id, $message, $type = 'popup_chat')
    {
        if ($this->isEmptyId($id)) {
            throw new InvalidArgumentException;
        }

        if (!$message) {
            throw new InvalidArgumentException;
        }

        if (!in_array($type, ['popup_chat', 'popup_small', 'popup_big', 'email'])) {
            throw new InvalidArgumentException;
        }

        $params = [
            'body' => $message,
            'type' => $type
        ];
        $res = $this->call('users/' . $id . '/sendmessage', $params, 'post');

        if ($res) {
            return true;
        }

        return false;
    }