State
in package
Class State
Handles loading and querying state data. This class loads state data from an external JSON file (presumably in the app's storage/states.json file) and provides methods to query state information.
Tags
Table of Contents
Properties
- $listCache : array<string|int, mixed>|null
- Cached list of states loaded from JSON.
Methods
- asSelectOptions() : string
- Builds <option> HTML tags from an array of StateInfo objects.
- count() : int
- Returns the total number of states and territories.
- dropDown() : string
- Returns an HTML <select> element for states.
- getAbbreviation() : string|null
- Gets the abbreviation for a state given a name or abbreviation.
- getAllCulturalRegions() : array<string|int, string>
- Returns a list of all unique cultural regions present in the state list.
- getAllRegions() : array<string|int, string>
- Returns a list of all unique geographic regions present in the state list.
- getAllStatehoodCategories() : array<string|int, string>
- Returns a list of all unique statehood categories present in the state list.
- getCapital() : string|null
- Gets the capital of a state or territory.
- getList() : array<string|int, mixed>
- Returns the full list of states and territories from the JSON file.
- getName() : string|null
- Gets the full name of a state.
- getOriginal13States() : array<string|int, StateInfo>
- Returns all the original 13 colonies.
- getState() : StateInfo|null
- Retrieves a specific state or territory by its abbreviation.
- getStateByCapital() : StateInfo|null
- Gets a StateInfo object by capital city.
- getStateRandom() : StateInfo|null
- Returns a random StateInfo object.
- getStatesByCulturalRegion() : array<string|int, StateInfo>
- Returns all states matching a cultural region.
- getStatesByFips() : array<string|int, StateInfo>
- Returns all states with a matching FIPS code.
- getStatesByRegion() : array<string|int, StateInfo>
- Returns all states in the given region.
- getStatesByStatehoodCategory() : array<string|int, StateInfo>
- Returns all states in a given statehood category.
- getStatesByTimezone() : array<string|int, StateInfo>
- Returns all states in a given timezone.
- getStatesWithRON() : array<string|int, StateInfo>
- Returns all states that allow Remote Online Notarization (RON).
- getTerritories() : array<string|int, StateInfo>
- Returns a list of U.S. territories (non-states).
- groupByRegion() : array<string|int, mixed>
- Groups all states by their geographic region.
- groupByTimezone() : array<string|int, mixed>
- Groups all states by their timezone.
- hasDaylightSaving() : bool
- Determines if the state observes Daylight Saving Time.
- isDeepSouth() : bool
- Checks if a state is part of the Deep South cultural region.
- isInRegion() : bool
- Checks if a state is in the given region.
- isInTimezone() : bool
- Checks if a state is in the given timezone.
- isLower48() : bool
- Checks if a state is in the contiguous lower 48.
- isMidwest() : bool
- Determines whether the given state or territory is located in the U.S. Midwest region.
- isNortheast() : bool
- Determines whether the given state or territory is located in the U.S. Northeast region.
- isOriginal13() : bool
- Determines whether the given state was one of the original 13 U.S. colonies.
- isRustBelt() : bool
- Determines whether the given state or territory is considered part of the Rust Belt cultural region.
- isSouth() : bool
- Checks if a state is in the Southern U.S.
- isTerritory() : bool
- Determines if the provided entry is a U.S. territory.
- isValidState() : bool
- Checks whether the given state abbreviation or name is valid.
- isWestern() : bool
- Checks if a state is part of the Western U.S.
- toSlug() : string
- Converts a state's name into a slug (lowercase, hyphenated).
Properties
$listCache
Cached list of states loaded from JSON.
protected
static array<string|int, mixed>|null
$listCache
= null
Methods
asSelectOptions()
Builds <option> HTML tags from an array of StateInfo objects.
public
static asSelectOptions(array<string|int, StateInfo> $states) : string
Parameters
- $states : array<string|int, StateInfo>
-
List of StateInfo objects.
Return values
string —HTML
count()
Returns the total number of states and territories.
public
static count() : int
Return values
int —Count of entries in the list.
dropDown()
Returns an HTML <select> element for states.
public
static dropDown() : string
Return values
string —HTML select dropdown of all states.
getAbbreviation()
Gets the abbreviation for a state given a name or abbreviation.
public
static getAbbreviation(string $stateOrAbbr) : string|null
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
string|null —Two-letter abbreviation, or null if not found.
getAllCulturalRegions()
Returns a list of all unique cultural regions present in the state list.
public
static getAllCulturalRegions() : array<string|int, string>
Return values
array<string|int, string> —Array of unique cultural region names.
getAllRegions()
Returns a list of all unique geographic regions present in the state list.
public
static getAllRegions() : array<string|int, string>
Return values
array<string|int, string> —Array of unique region names.
getAllStatehoodCategories()
Returns a list of all unique statehood categories present in the state list.
public
static getAllStatehoodCategories() : array<string|int, string>
Return values
array<string|int, string> —Array of unique statehood categories.
getCapital()
Gets the capital of a state or territory.
public
static getCapital(string $stateOrAbbr) : string|null
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
string|null —Capital city, or null if not found.
getList()
Returns the full list of states and territories from the JSON file.
public
static getList([string $statesJsonFilename = 'states.json' ]) : array<string|int, mixed>
Parameters
- $statesJsonFilename : string = 'states.json'
Return values
array<string|int, mixed> —Associative array of states indexed by abbreviation.
getName()
Gets the full name of a state.
public
static getName(string $stateOrAbbr) : string|null
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
string|null —Full name of the state.
getOriginal13States()
Returns all the original 13 colonies.
public
static getOriginal13States() : array<string|int, StateInfo>
Return values
array<string|int, StateInfo> —Original 13 states.
getState()
Retrieves a specific state or territory by its abbreviation.
public
static getState(string $stateOrAbbr) : StateInfo|null
Parameters
- $stateOrAbbr : string
-
The state abbreviation (e.g., 'TX') or name (e.g., 'Texas').
Return values
StateInfo|null —The StateInfo object for the state or territory, or null if not found.
getStateByCapital()
Gets a StateInfo object by capital city.
public
static getStateByCapital(string $capital) : StateInfo|null
Parameters
- $capital : string
-
Capital city name.
Return values
StateInfo|null —StateInfo object, or null if not found.
getStateRandom()
Returns a random StateInfo object.
public
static getStateRandom() : StateInfo|null
Return values
StateInfo|null —A random state or territory.
getStatesByCulturalRegion()
Returns all states matching a cultural region.
public
static getStatesByCulturalRegion(string $region) : array<string|int, StateInfo>
Parameters
- $region : string
-
Cultural region name.
Return values
array<string|int, StateInfo> —Matching states.
getStatesByFips()
Returns all states with a matching FIPS code.
public
static getStatesByFips(string $fips) : array<string|int, StateInfo>
Parameters
- $fips : string
-
FIPS code to match.
Return values
array<string|int, StateInfo> —List of matches.
getStatesByRegion()
Returns all states in the given region.
public
static getStatesByRegion(string $region) : array<string|int, StateInfo>
Parameters
- $region : string
-
Region name (e.g., 'West').
Return values
array<string|int, StateInfo> —List of StateInfo objects.
getStatesByStatehoodCategory()
Returns all states in a given statehood category.
public
static getStatesByStatehoodCategory(string $category) : array<string|int, StateInfo>
Parameters
- $category : string
-
Category name (e.g., 'Original', 'Annexed').
Return values
array<string|int, StateInfo> —List of matches.
getStatesByTimezone()
Returns all states in a given timezone.
public
static getStatesByTimezone(string $timezone) : array<string|int, StateInfo>
Parameters
- $timezone : string
-
Timezone name (e.g., 'Central').
Return values
array<string|int, StateInfo> —List of StateInfo objects.
getStatesWithRON()
Returns all states that allow Remote Online Notarization (RON).
public
static getStatesWithRON() : array<string|int, StateInfo>
Return values
array<string|int, StateInfo> —States with RON support.
getTerritories()
Returns a list of U.S. territories (non-states).
public
static getTerritories() : array<string|int, StateInfo>
Return values
array<string|int, StateInfo> —Territories only.
groupByRegion()
Groups all states by their geographic region.
public
static groupByRegion() : array<string|int, mixed>
Return values
array<string|int, mixed> —Associative array where the key is the region name and the value is a list of StateInfo objects.
groupByTimezone()
Groups all states by their timezone.
public
static groupByTimezone() : array<string|int, mixed>
Return values
array<string|int, mixed> —Associative array where the key is the timezone name and the value is a list of StateInfo objects.
hasDaylightSaving()
Determines if the state observes Daylight Saving Time.
public
static hasDaylightSaving(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
bool —True if observes DST.
isDeepSouth()
Checks if a state is part of the Deep South cultural region.
public
static isDeepSouth(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
bool —True if Deep South.
isInRegion()
Checks if a state is in the given region.
public
static isInRegion(string $stateOrAbbr, string $region) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
- $region : string
-
Region to check.
Return values
bool —True if in region.
isInTimezone()
Checks if a state is in the given timezone.
public
static isInTimezone(string $stateOrAbbr, string $timezone) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
- $timezone : string
-
Timezone to check.
Return values
bool —True if in timezone.
isLower48()
Checks if a state is in the contiguous lower 48.
public
static isLower48(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
bool —True if in the Lower 48.
isMidwest()
Determines whether the given state or territory is located in the U.S. Midwest region.
public
static isMidwest(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
The state's full name or abbreviation.
Return values
bool —True if the state is in the Midwest region; false otherwise.
isNortheast()
Determines whether the given state or territory is located in the U.S. Northeast region.
public
static isNortheast(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
The state's full name or abbreviation.
Return values
bool —True if the state is in the Northeast region; false otherwise.
isOriginal13()
Determines whether the given state was one of the original 13 U.S. colonies.
public
static isOriginal13(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
The state's full name or abbreviation.
Return values
bool —True if the state was part of the original 13 colonies; false otherwise.
isRustBelt()
Determines whether the given state or territory is considered part of the Rust Belt cultural region.
public
static isRustBelt(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
The state's full name or abbreviation.
Return values
bool —True if the state is part of the Rust Belt; false otherwise.
isSouth()
Checks if a state is in the Southern U.S.
public
static isSouth(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
bool —True if southern.
isTerritory()
Determines if the provided entry is a U.S. territory.
public
static isTerritory(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
bool —True if it is a territory, false if state or not found.
isValidState()
Checks whether the given state abbreviation or name is valid.
public
static isValidState(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
bool —True if valid, false otherwise.
isWestern()
Checks if a state is part of the Western U.S.
public
static isWestern(string $stateOrAbbr) : bool
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
bool —True if western.
toSlug()
Converts a state's name into a slug (lowercase, hyphenated).
public
static toSlug(string $stateOrAbbr) : string
Parameters
- $stateOrAbbr : string
-
Abbreviation or name.
Return values
string —Slug string or empty string if not found.