<commit_before><?php
class FiltersGenerator extends ClientGeneratorFromPhp 
{
	private $_txt = "";
	
	protected function writeHeader()
	{
		
	}
	
	protected function writeFooter()
	{
		
	}
	
	protected function writeBeforeServices()
	{
		
	}
	
	protected function writeBeforeService(KalturaServiceReflector $serviceReflector)
	{
		
	}
	
	protected function writeServiceAction($serviceId, $serviceName, $action, $actionParams, $outputTypeReflector)
	{
		
	}
	
	protected function writeAfterService(KalturaServiceReflector $serviceReflector)
	{
		
	}
	
	protected function writeAfterServices()
	{
		
	}
	
	protected function writeBeforeTypes()
	{
		
	}

	protected function writeType(KalturaTypeReflector $type)
	{
		if ($type->isFilterable())
		{
			$this->writeFilterForType($type);
			$this->writeOrderByEnumForType($type);
		}
	}
	
	private function writeFilterForType(KalturaTypeReflector $type)
	{
		$map = KAutoloader::getClassMap();
		if(!isset($map[$type->getType()]))
			return;
		
		$filterClassName = $type->getType() . "Filter";
		
		$filterPath = dirname($map[$type->getType()]) . "/filters/$filterClassName.php";
		$this->_txt = "";
			
		
		$parentType = $type;
		while(1)
		{
			$parentType = $parentType->getParentTypeReflector();
			if ($parentType === null || $parentType->isFilterable())
				break;			
		}
		
		$partnetClassName = ($parentType ? $parentType->getType() . "Filter" : "KalturaFilter");
		
		$this->appendLine("<?php");
		$this->appendLine("/**");
		$this->appendLine(" * @package api");
		$this->appendLine(" * @subpackage filters");
		$this->appendLine(" */");
		$this->appendLine("class $filterClassName extends $partnetClassName");
		$this->appendLine("{");
		$this->appendLine("	private \$map_between_objects = array");
		$this->appendLine("	(");
		
		// properies map
		foreach($type->getCurrentProperties() as $prop)
		{
			$filters = $prop->getFilters();
			foreach($filters as $filter)
			{
				if ($filter != "order")
				{
					$propertyName = $this->formatFilterPropertyName($filter, $prop->getName());
					$filterName = $this->formatFilterPropertyValue($filter, $prop->getName());
					$this->appendLine("		\"".$propertyName."\" => \"$filterName\",");
				}
			}
		}
		
		// extra filters properties map
		$extraFilters = null;
		$reflectionClass = new ReflectionClass($type->getType());
		// invoke getExtraFilter only if it was defined in the current class
		if ($reflectionClass->getMethod("getExtraFilters")->getDeclaringClass()->getName() === $reflectionClass->getName()) 
		{
			$extraFilters = $type->getInstance()->getExtraFilters();<commit_msg>Generates base filter and editable filter.<commit_after><?php
class FiltersGenerator extends ClientGeneratorFromPhp 
{
	private $_txt = "";
	
	protected function writeHeader()
	{
		
	}
	
	protected function writeFooter()
	{
		
	}
	
	protected function writeBeforeServices()
	{
		
	}
	
	protected function writeBeforeService(KalturaServiceReflector $serviceReflector)
	{
		
	}
	
	protected function writeServiceAction($serviceId, $serviceName, $action, $actionParams, $outputTypeReflector)
	{
		
	}
	
	protected function writeAfterService(KalturaServiceReflector $serviceReflector)
	{
		
	}
	
	protected function writeAfterServices()
	{
		
	}
	
	protected function writeBeforeTypes()
	{
		
	}

	protected function writeType(KalturaTypeReflector $type)
	{
		if ($type->isFilterable())
		{
			$this->writeBaseFilterForType($type);
			$this->writeFilterForType($type);
			$this->writeOrderByEnumForType($type);
		}
	}
	
	private function writeFilterForType(KalturaTypeReflector $type)
	{
		$map = KAutoloader::getClassMap();
		if(!isset($map[$type->getType()]))
			return;
		
		$filterClassName = $type->getType() . "Filter";
		$filterBaseClassName = $type->getType() . "BaseFilter";
		
		$filterPath = dirname($map[$type->getType()]) . "/filters/$filterClassName.php";
		if(file_exists($filterPath))
		{
			KalturaLog::notice("Filter already exists [$filterPath]");
			return;
		}
		$this->_txt = "";
			
		
		$parentType = $type;
		while(1)
		{
			$parentType = $parentType->getParentTypeReflector();
			if ($parentType === null || $parentType->isFilterable())
				break;			
		}
		
		$partnetClassName = ($parentType ? $parentType->getType() . "Filter" : "KalturaFilter");
		
		$this->appendLine("<?php");
		$this->appendLine("/**");
		$this->appendLine(" * @package api");
		$this->appendLine(" * @subpackage filters");
		$this->appendLine(" */");
		$this->appendLine("class $filterClassName extends $filterBaseClassName");
		$this->appendLine("{");
		$this->appendLine("}");
		
		$this->writeToFile($filterPath, $this->_txt);
	}
	
	private function writeBaseFilterForType(KalturaTypeReflector $type)
	{
		$map = KAutoloader::getClassMap();
		if(!isset($map[$type->getType()]))
			return;
		
		$filterClassName = $type->getType() . "BaseFilter";
		
		$filterPath = dirname($map[$type->getType()]) . "/filters/base/$filterClassName.php";
		$this->_txt = "";
			
		
		$parentType = $type;
		while(1)
		{
			$parentType = $parentType->getParentTypeReflector();
			if ($parentType === null || $parentType->isFilterable())
				break;			
		}
		
		$partnetClassName = ($parentType ? $parentType->getType() . "Filter" : "KalturaFilter");
		
		$this->appendLine("<?php");
		$this->appendLine("/**");
		$this->appendLine(" * @package api");
		$this->appendLine(" * @subpackage filters.base");
		$this->appendLine(" * @abstract");
		$this->appendLine(" */");
		$this->appendLine("class $filterClassName extends $partnetClassName");
		$this->appendLine("{");
		$this->appendLine("	private \$map_between_objects = array");
		$this->appendLine("	(");
		
		// properies map
		foreach($type->getCurrentProperties() as $prop)
		{
			$filters = $prop->getFilters();
			foreach($filters as $filter)
			{
				if ($filter != "order")
				{
					$propertyName = $this->formatFilterPropertyName($filter, $prop->getName());
					$filterName = $this->formatFilterPropertyValue($filter, $prop->getName());
					$this->appendLine("		\"".$propertyName."\" => \"$filterName\",");
				}
			}
		}
		
		// extra filters properties map
		$extraFilters = null;
		$reflectionClass = new ReflectionClass($type->getType());
		// invoke getExtraFilter only if it was defined in the current class
		if ($reflectionClass->getMethod("getExtraFilters")->getDeclaringClass()->getName() === $reflectionClass->getName()) 
		{
			$extraFilters = $type->getInstance()->getExtraFilters();
{'fraction_non_alphanumeric': 0.17194780987884437, 'fraction_numerical': 0.00046598322460391424, 'mean_word_length': 4.365833333333334, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6621102', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2023, 'n_words': 345}