Process components

@param   String $type  - The type
@param   String $toDir - The target

@return  void

@since   1.0
164797
private function mapDir($type, $toDir)
	{
		// Check if dir exists
		if (is_dir($this->getSourceFolder()))
		{
			$dirHandle = opendir($this->getSourceFolder());

			while (false !== ($element = readdir($dirHandle)))
			{
				if (substr($element, 0, 1) != '.')
				{
					$this->symlink($this->getSourceFolder() . '/' . $element, $toDir . '/' . $type . '/' . $element);
				}
			}
		}
	}
446772
public function setTypes($attr, $type = null)
    {
        if (is_array($attr))
            $this->inputType = array_merge($this->inputType, $attr);
        else
            $this->inputType[$attr] = $type;

        return $this;
    }
409265
public function setType(string $type): void {
		if ($this->compiled) {
			throw new ResponseException("Attempt to alter response after compilation.", ResponseException::AFTER_COMPILE_ALTERATION);
		}
		
		$type = strtolower($type);
		
		if (!in_array($type, ["html", "json", "text", "redirect"])) {
			throw new ResponseException("Unexpected response type: $type.", ResponseException::UNKNOWN_RESPONSE_TYPE);
		}
		
		$this->type = $type;
	}
1023077
protected function startRendering($type, ParsedTemplateInterface $parsedTemplate, RenderingContextInterface $renderingContext)
    {
        array_push($this->renderingStack, array('type' => $type, 'parsedTemplate' => $parsedTemplate, 'renderingContext' => $renderingContext));
    }
199877
public function my_dispatchEvent($type, $data)
    {
        foreach ($this->client as $client) {
            $client->dispatchEvent($type, $data);
        }
    }
56789
public function clear($type)
    {
        if ($type == self::TYPE_ALL) {
            $indexes = $this->getAllIndexes();
        } else {
            $indexes = $this->getIndexes($type);
        }

        foreach ($indexes as $index) {
            $index->clear();
        }
    }
782882
public function finish($type = 'NORMAL')
    {
        $this->finished = true;
        if ($type === 'BROKEN') {
            $this->res->error = Connection::getLastError();
        } else {
            if ($type !== 'NORMAL') {
                $this->res->error = ucfirst(strtolower($type));
            }
        }
        // gzip decode
        $encoding = $this->res->getHeader('content-encoding');
        if ($encoding !== null && strstr($encoding, 'gzip')) {
            $this->res->body = Client::gzdecode($this->res->body);
        }
        // parser
        $this->res->timeCost = microtime(true) - $this->timeBegin;
        $this->cli->runParser($this->res, $this->req, $this->key);
        // conn
        if ($this->conn) {
            // close conn
            $close = $this->res->getHeader('connection');
            $this->conn->close($type !== 'NORMAL' || !strcasecmp($close, 'close'));
            $this->conn = null;
            // redirect
            if (($this->res->status === 301 || $this->res->status === 302)
                && $this->res->numRedirected < $this->req->getMaxRedirect()
                && ($location = $this->res->getHeader('location')) !== null
            ) {
                Client::debug('redirect to \'', $location, '\'');
                $req = $this->req;
                if (!preg_match('/^https?:\/\//i', $location)) {
                    $pa = $req->getUrlParams();
                    $url = $pa['scheme'] . '://' . $pa['host'];
                    if (isset($pa['port'])) {
                        $url .= ':' . $pa['port'];
                    }
                    if (substr($location, 0, 1) == '/') {
                        $url .= $location;
                    } else {
                        $url .= substr($pa['path'], 0, strrpos($pa['path'], '/') + 1) . $location;
                    }
                    $location = $url; /// FIXME: strip relative '../../'
                }
                // change new url
                $prevUrl = $req->getUrl();
                $req->setUrl($location);
                if (!$req->getHeader('referer')) {
                    $req->setHeader('referer', $prevUrl);
                }
                if ($req->getMethod() !== 'HEAD') {
                    $req->setMethod('GET');
                }
                $req->clearCookie();
                $req->setHeader('host', null);
                $req->setHeader('x-server-ip', null);
                $req->setHeader('content-type', null);
                $req->setBody(null);
                // reset response
                $this->res->numRedirected++;
                $this->finished = $this->headerOk = false;
                return $this->res->reset();
            }
        }
        Client::debug('finished', $this->res->hasError() ? ' (' . $this->res->error . ')' : '');
        $this->req = $this->cli = null;
    }
191175
public function calculate(&$total, $data, &$components, array $price_rule)
    {
        try {
            $callback = Handler::get($this->getTypes(), $price_rule['value_type'], 'calculate');
            call_user_func_array($callback, array(&$total, &$components, $price_rule, $data));
        } catch (Exception $ex) {
            trigger_error($ex->getMessage());
        }
    }
915233
public function removeType(string $type)
    {
        if (!$this->removing && Type::hasType($type)) {
            $this->removing = true;
            Type::overrideType($type, null);
        }

        $this->removing = false;
        unset($this->types[$type]);
    }
952851
protected function runCallbacks($type)
	{
		// make sure we have callbacks of this type
		if (array_key_exists($type, $this->callbacks))
		{
			// run the defined callbacks
			foreach ($this->callbacks[$type] as $callback)
			{
				// check if the callback is valid
				if (is_callable($callback))
				{
					// call the defined callback
					$result = call_user_func_array($callback, array(&$this));

					// and process the results. we need FileError instances only
					foreach ((array) $result as $entry)
					{
						if (is_object($entry) and $entry instanceOf FileError)
						{
							$this->errors[] = $entry;
						}
					}

					// update the status of this validation
					$this->isValid = empty($this->errors);
				}
			}
		}
	}
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;
	}
421774
public function onAddedToType(TypeInterface &$type)
    {
        parent::onAddedToType($type);

        if ($this->getAddIndex()) {
            $type->addIndex(new Index($this->name));
        }

        $type->addTrait(UpdatedAtInterface::class, UpdatedAtInterfaceImplementation::class)->serialize($this->name);
    }
865371
public function onAddedToType(TypeInterface &$type)
    {
        parent::onAddedToType($type);

        if ($this->getAddIndex()) {
            $type->addIndex(new Index($this->name));
        }

        $type->addTrait(PositionInterface::class, PositionInterfaceImplementation::class);
    }
178006
public function findComponentsByType($type)
    {
        $components = [];
        foreach ($this->components as $component) {
            if ($component->hasType($type)) {
                $components[] = $component;
            }
        }

        return $components;
    }
570746
public static function create( $type, array $props )
    {
        try {
            $component = self::create_registered_component($type, $props);
        } catch (\RuntimeException $ex) {
            $component = self::create_core_component($type, $props);
        }
        
        return $component;
    }
1054079
public function process_child( $type ) {

		if ( isset( $this->struct[ $type ]['id'] ) ) {
			$this->{$type}( $this->struct[ $type ]['id'], $this->struct[ $type ] );
		} else {
			$this->process_children( $type );
		}

	}
601113
public function clear( $type = null ) 
	{
		if ( is_null( $type ) )
		{
			$this->assets = array();
		}
		else
		{
			if ( isset( $this->assets[$type] ) )
			{
				$this->assets[$type] = array();
			}
		}
	}