<?php
/**
 * Copyright © 2024 ExacTI Technology Solutions. All rights reserved.
 * GPLv3 General License.
 * https://exacti.com.br
 * Phacil PHP Framework - https://github.com/exacti/phacil-framework
 */

namespace Phacil\Framework;

class PreActions implements \Phacil\Framework\Api\PreActions {
	/**
	 * 
	 * @var \Phacil\Framework\Action[]
	 */
	protected $handlers = array();

	private $preActions = [];

	/**
	 * 
	 * @var \Phacil\Framework\Registry
	 */
	private $registry;

	public function __construct(array $preActions, \Phacil\Framework\Registry $registry){
		$this->preActions = $preActions;
		$this->registry = $registry;

		$this->createPreActions();
	}

	protected function createPreActions() {
		foreach ($this->preActions as $preAction){
			$this->handlers[] = $this->registry->create(\Phacil\Framework\Action::class, $preAction);
		}
	}

	/** {@inheritdoc}  */
	public function getHandlers() {
		return $this->handlers;
	}

	/**
	 * @param int $actionKey 
	 * @return void 
	 */
	public function executedActionHandler($actionKey){
		unset($this->handlers[$actionKey]);
	}
}