You are here

public static function RealisticDummyContentEnvironment::filenameRadical in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::filenameRadical()
  2. 7.2 api/src/includes/RealisticDummyContentEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentEnvironment::filenameRadical()

Returns the name radical of a filename.

The following examples will all return "two.txt"

two.txt two.txt.attribute.txt two.txt.attribute1.txt

If >2 periods are present in the file name, then what is between the last and next to last period is removed, for example:

a.b.c => a.c a.b.c.d => a.b.d a.b => a.b a => a

Parameters

string $filename: A filename string, for example 'a.b.txt'.

Return value

string The name radical of this file, for example a.txt.

Throws

RealisticDummyContentException

File

api/src/includes/RealisticDummyContentEnvironment.php, line 358

Class

RealisticDummyContentEnvironment
The abstract base environment.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

public static function filenameRadical($filename) {
  if (!is_string($filename)) {
    throw new RealisticDummyContentException('Please pass ' . __FUNCTION__ . ' a string as a filename, not a ' . gettype($filename));
  }
  return self::replace($filename, '\\1\\3');
}