Return first found of an array of templates

@param  array       $templates
@return bool|string
973844
private function findMany(array $templates)
    {
        $found = false;
        while (! $found && ! empty($templates)) {
            $found = $this->find(array_shift($templates));
        }

        return $found;
    }
422965
public static function SetTemplates ($templates = []) {
		if (gettype(static::$templates) == 'array') {
			static::$templates = (array) $templates;
		} else {
			static::$templates = (object) $templates;
		}
		return static::$templates;
	}
522291
private function loadTemplate($template)
    {
        if (!array_key_exists($template, $this->templateCache)) {
            $this->templateCache[$template] = $this->twig->loadTemplate($template);
        }

        return $this->templateCache[$template];
    }
71877
public function getFirstTable($tables=null)
    {
        if (!$tables) {
            $tables = static::getQuery()->get('table');
        }
        if ($tables) {
            if (is_string($tables)) {
                return DataHelper::explode(',\s*', $tables)[0];
            } elseif (is_array($tables)) {
                return static::getFirstTable(current($tables));
            }
        }
        
        return $tables;
    }
1073291
public function single( $templates ) {

		$templates = [];

		// Get the queried post.
		$post = get_queried_object();

		// Decode the post name.
		$name = urldecode( $post->post_name );

		// Check for a custom post template.
		$custom = get_page_template_slug( $post->ID );

		if ( $custom ) {
			$templates[] = $custom;
		}

		// If viewing an attachment page, handle the files by mime type.
		if ( is_attachment() ) {

			// Split the mime type into two distinct parts.
			$type    = get_post_mime_type( $post );
			$subtype = '';

			if ( false !== strpos( $type, '/' ) ) {
				list( $type, $subtype ) = explode( '/', $type );
			}

			if ( $subtype ) {
				$templates[] = "attachment-{$type}-{$subtype}.php";
				$templates[] = "attachment-{$subtype}.php";
			}

			$templates[] = "attachment-{$type}.php";

		// If not viewing an attachment page.
		} else {

			// Add a post ID template.
			$templates[] = "single-{$post->post_type}-{$post->ID}.php";
			$templates[] = "{$post->post_type}-{$post->ID}.php";

			// Add a post name (slug) template.
			$templates[] = "single-{$post->post_type}-{$name}.php";
			$templates[] = "{$post->post_type}-{$name}.php";
		}

		// Add a template based off the post type name.
		$templates[] = "single-{$post->post_type}.php";
		$templates[] = "{$post->post_type}.php";

		// Allow for WP standard 'single' template.
		$templates[] = 'single.php';

		// Return the template hierarchy.
		return $templates;
	}
1133415
public static function findFirst($parameters = null)
    {
        $result = parent::findFirst($parameters);

        if ($result) {
            $customFields = $result->getAllCustomFields();

            if (is_array($customFields)) {
                //field the object
                foreach ($result->getAllCustomFields() as $key => $value) {
                    $result->{$key} = $value;
                }
            }
        }

        return $result;
    }
977605
public function template($template = null)
    {
        if (is_null($template)) {
            return $this->template;
        } else {
            $this->template = $template;
        }
    }
684778
public function findAllTemplates()
    {
        if (null !== $this->templates) {
            return $this->templates;
        }

        $templates = array();

        foreach ($this->paths as $dir) {
            $templates = array_merge($templates, $this->findTemplatesInFolder($dir));
        }

        return $this->templates = $templates;
    }
469653
protected function _compileTemplates(array $templates = [])
    {
        if (empty($templates)) {
            $templates = array_keys($this->_config);
        }
        foreach ($templates as $name) {
            $template = $this->get($name);
            if ($template === null) {
                $this->_compiled[$name] = [null, null];
            }

            $template = str_replace('%', '%%', $template);
            preg_match_all('#\{\{([\w\._]+)\}\}#', $template, $matches);
            $this->_compiled[$name] = [
                str_replace($matches[0], '%s', $template),
                $matches[1]
            ];
        }
    }
1107185
function loadTemplates()
    {
        $result[0] = array();
        $result[1] = array();
        $templates = Templates::getInstance();
        $list = $templates->enum();
        $result[0]= array_values($list);
        $result[1]= array_keys($list);
        return $result;
    }
1204678
public function getTemplateRelativePath($template)
	{
	    $rootPath = Config::getRootPath();
	    return str_replace($rootPath, '', $this->getTemplatePath()) . $this->_getRelativeTemplate($template) . $this->getSuffix();
	}
471153
public function partial($template, $vars=array())
	{
		return $this->_renderTemplate($template,
			array_merge($this->_vars, $vars));
	}
469033
protected function getTemplate($template)
    {
        $path = realpath(__DIR__.'/../templates/'.$template.'.txt');

        return $this->files->get($path);
    }
779745
public function find($template)
    {
        if (!$this->supports($template)) {
            return false;
        }

        foreach ($this->paths as $path) {
            $filePath = "{$path}/{$template}";

            if (file_exists($filePath)) {
                return $filePath;
            }
        }

        return false;
    }
831702
public function choose_template( $templates ) {
		// Change $templates into array, if needed
		if ( !is_array($templates) ) {
			$templates = (array) $templates;
		}

		// Get Twig loader
		$loader = $this->get_loader();

		// Run through template array
		foreach ( $templates as $template ) {

			// Remove any whitespace around the template name
			$template = trim( $template );
			// Use the Twig loader to test for existance
			if ( $loader->exists($template) ) {
				// Return name of existing template
				return $template;
			}
		}

		// No existing template was found
		return false;
	}
1257139
protected function getOutTemplate($template = 'default') {
		// check for current locale
		if ($this->locale != '') {
			$templatefile = $this->templatespath.'/'.$this->locale.'/'.$this->outtemplateprefix.$template.'.htm';
			
			if (file_exists($templatefile)) {
				return $this->locale.'/'.$this->outtemplateprefix.$template;
			}
		}
		
		// if not found, check for default locale
		if ($this->deflocale != '') {
			$templatefile = $this->templatespath.'/'.$this->deflocale.'/'.$this->outtemplateprefix.$template.'.htm';
			
			if (file_exists($templatefile)) {
				return $this->deflocale.'/'.$this->outtemplateprefix.$template;
			}
		}
		
		// if not found then check in root
		$templatefile = $this->templatespath.'/'.$this->outtemplateprefix.$template.'.htm';
			
		if (file_exists($templatefile)) {
			return $this->outtemplateprefix.$template;
		}
		
		// out template not found
		return null;
	}
1086153
protected function getTwigTemplatesIn($directories)
    {
        if (count($directories) === 0) {
            return array();
        }
        $templates = Finder::create()->in($directories)->files()->name('*.*.twig');
        $templates = iterator_to_array($templates, false);
        $templates = array_map(function (SplFileInfo $file) {
            return $file->getRealPath();
        }, $templates);
        return $templates;
    }