pub(crate) const FACADE_CONTRACTS: &[(&str, &str, &str)] = &[
("Cache", "Illuminate\\Contracts\\Cache\\Repository", "cache"),
("Auth", "Illuminate\\Contracts\\Auth\\Factory", "auth"),
("Log", "Psr\\Log\\LoggerInterface", "log"),
("DB", "Illuminate\\Database\\ConnectionInterface", "db"),
(
"Storage",
"Illuminate\\Contracts\\Filesystem\\Factory",
"storage",
),
("Mail", "Illuminate\\Contracts\\Mail\\Mailer", "mailer"),
("Queue", "Illuminate\\Contracts\\Queue\\Queue", "queue"),
(
"Event",
"Illuminate\\Contracts\\Events\\Dispatcher",
"events",
),
(
"Session",
"Illuminate\\Contracts\\Session\\Session",
"session",
),
(
"Config",
"Illuminate\\Contracts\\Config\\Repository",
"config",
),
(
"Validator",
"Illuminate\\Contracts\\Validation\\Factory",
"validator",
),
("Redis", "Illuminate\\Redis\\RedisManager", "redis"),
("Http", "Illuminate\\Http\\Client\\Factory", "http"),
];
pub(crate) fn lookup(facade_name: &str) -> Option<(&'static str, &'static str)> {
FACADE_CONTRACTS
.iter()
.find(|(name, _, _)| *name == facade_name)
.map(|(_, contract, prop)| (*contract, *prop))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn looks_up_known_facade() {
assert_eq!(
lookup("Cache"),
Some(("Illuminate\\Contracts\\Cache\\Repository", "cache"))
);
}
#[test]
fn none_for_unknown_name() {
assert_eq!(lookup("SomeUnrelatedClass"), None);
}
#[test]
fn case_sensitive_no_match_for_lowercase() {
assert_eq!(lookup("cache"), None);
}
}