src/ChickenWire/Controller.php
private function _guessExtension($filename, $suffix = '.php')
		{


			// Content type chosen?
			$possibleExtensions = array();
			$allAccepted = false;
			if (!is_null($this->contentType)) {

				// Get extensions
				$possibleExtensions = $this->contentType->getExtensions();

			} else {

				// Collect extensions for all types
				foreach ($this->request->preferredContent as $type) {
					$possibleExtensions = array_merge($possibleExtensions, $type->getExtensions());
					if ($type->type == Mime::ALL) {
						$allAccepted = true;
					}
				}

			}

			// See if any of 'em exist
			foreach ($possibleExtensions as $ext) {
				
				// Something there?
				$tryFilename = $filename . ".$ext$suffix";
				if (file_exists($tryFilename)) {
					return $tryFilename;
				}

			}

			// Nothing found... Was */* one of accepted headers?
			if ($allAccepted) {

				// Check dir
				$dir = dirname($filename);
				if (!file_exists($dir) || !is_dir($dir)) {
					return false;
				}

				// File part
				$searchFor = substr($filename, strlen($dir) + 1);

				// Look in the directory				
				$dh = opendir($dir);
				while (false !== ($file = readdir($dh))) {

					// Known content type?
					if (Str::getContentExtension($file))

					// Starts with our template and ends with .php?
					if (is_file($dir . '/' . $file) 
							&& preg_match('/^' . preg_quote($searchFor) . '\.([a-z]+)' . preg_quote($suffix) . '$/', $file)
							&& Mime::byExtension(Str::getContentExtension($file)) !== false) {

						// Well, we found a file with an extension, so let's serve it
						return $dir . '/' . $file;

					}
					
				}
				

			}

			// Nothing :(
			return false;

		}
private function _guessExtension($filename, $suffix = '.php')
		{


			// Content type chosen?
			$possibleExtensions = array();
			$allAccepted = false;
			if (!is_null($this->contentType)) {

				// Get extensions
				$possibleExtensions = $this->contentType->getExtensions();

			} else {

				// Collect extensions for all types
				foreach ($this->request->preferredContent as $type) {
					$possibleExtensions = array_merge($possibleExtensions, $type->getExtensions());
					if ($type->type == Mime::ALL) {
						$allAccepted = true;
					}
				}

			}

			// See if any of 'em exist
			foreach ($possibleExtensions as $ext) {
				
				// Something there?
				$tryFilename = $filename . ".$ext$suffix";
				if (file_exists($tryFilename)) {
					return $tryFilename;
				}

			}

			// Nothing found... Was */* one of accepted headers?
			if ($allAccepted) {

				// Check dir
				$dir = dirname($filename);
				if (!file_exists($dir) || !is_dir($dir)) {
					return false;
				}

				// File part
				$searchFor = substr($filename, strlen($dir) + 1);

				// Look in the directory				
				$dh = opendir($dir);
				while (false !== ($file = readdir($dh))) {

					// Known content type?
					if (Str::getContentExtension($file))

					// Starts with our template and ends with .php?
					if (is_file($dir . '/' . $file) 
							&& preg_match('/^' . preg_quote($searchFor) . '\.([a-z]+)' . preg_quote($suffix) . '$/', $file)
							&& Mime::byExtension(Str::getContentExtension($file)) !== false) {

						// Well, we found a file with an extension, so let's serve it
						return $dir . '/' . $file;

					}
					
				}
				

			}

			// Nothing :(
			return false;

		}
private function _guessExtension ( $ filename , $ suffix = '.php' ) { // Content type chosen? $ possibleExtensions = array ( ) ; $ allAccepted = false ; if ( ! is_null ( $ this -> contentType ) ) { // Get extensions $ possibleExtensions = $ this -> contentType -> getExtensions ( ) ; } else { // Collect extensions for all types foreach ( $ this -> request -> preferredContent as $ type ) { $ possibleExtensions = array_merge ( $ possibleExtensions , $ type -> getExtensions ( ) ) ; if ( $ type -> type == Mime :: ALL ) { $ allAccepted = true ; } } } // See if any of 'em exist foreach ( $ possibleExtensions as $ ext ) { // Something there? $ tryFilename = $ filename . ".$ext$suffix" ; if ( file_exists ( $ tryFilename ) ) { return $ tryFilename ; } } // Nothing found... Was */* one of accepted headers? if ( $ allAccepted ) { // Check dir $ dir = dirname ( $ filename ) ; if ( ! file_exists ( $ dir ) || ! is_dir ( $ dir ) ) { return false ; } // File part $ searchFor = substr ( $ filename , strlen ( $ dir ) + 1 ) ; // Look in the directory				 $ dh = opendir ( $ dir ) ; while ( false !== ( $ file = readdir ( $ dh ) ) ) { // Known content type? if ( Str :: getContentExtension ( $ file ) ) // Starts with our template and ends with .php? if ( is_file ( $ dir . '/' . $ file ) && preg_match ( '/^' . preg_quote ( $ searchFor ) . '\.([a-z]+)' . preg_quote ( $ suffix ) . '$/' , $ file ) && Mime :: byExtension ( Str :: getContentExtension ( $ file ) ) !== false ) { // Well, we found a file with an extension, so let's serve it return $ dir . '/' . $ file ; } } } // Nothing :( return false ; }
Guess a file extension for the given extensionless filename, based
on the request headers, or chosen content type.

@param  string $filename The filename without extension to complete. This already needs to be complete path.
@param  string $suffix   (default '.php') Suffix to put at then end of every filename to try.
@return string|false     The completed filename, when a suitable file was found, or false if not.
Guess a file extension for the given extensionless filename based on the request headers or chosen content type .