laravel 服务别名的理解
先看下容器别名数组属性是什么
container aliases属性 $arr = [ "Illuminate\Foundation\Application" => "app" "Illuminate\Contracts\Container\Container" => "app" "Illuminate\Contracts\Foundation\Application" => "app" "Psr\Container\ContainerInterface" => "app" "Illuminate\Auth\AuthManager" => "auth" "Illuminate\Contracts\Auth\Factory" => "auth" "Illuminate\Contracts\Auth\Guard" => "auth.driver" "Illuminate\View\Compilers\BladeCompiler" => "blade.compiler" "Illuminate\Cache\CacheManager" => "cache" "Illuminate\Contracts\Cache\Factory" => "cache" "Illuminate\Cache\Repository" => "cache.store" "Illuminate\Contracts\Cache\Repository" => "cache.store" "Psr\SimpleCache\CacheInterface" => "cache.store" "Symfony\Component\Cache\Adapter\Psr16Adapter" => "cache.psr6" "Symfony\Component\Cache\Adapter\AdapterInterface" => "cache.psr6" "Psr\Cache\CacheItemPoolInterface" => "cache.psr6" "Illuminate\Redis\Connections\Connection" => "redis.connection" "Illuminate\Contracts\Redis\Connection" => "redis.connection" "Illuminate\Http\Request" => "request" "Symfony\Component\HttpFoundation\Request" => "request" "Illuminate\Routing\Router" => "router" "Illuminate\Contracts\Routing\Registrar" => "router" "Illuminate\Contracts\Routing\BindingRegistrar" => "router" "Illuminate\Session\SessionManager" => "session" "Illuminate\Session\Store" => "session.store" "Illuminate\Contracts\Session\Session" => "session.store" "Illuminate\Routing\UrlGenerator" => "url" "Illuminate\Contracts\Routing\UrlGenerator" => "url" "Illuminate\Validation\Factory" => "validator" "Illuminate\Contracts\Validation\Factory" => "validator" "Illuminate\View\Factory" => "view" "Illuminate\Contracts\View\Factory" => "view" ]
再看下 抽象属性
abstractAliases $arr= [ "app" => array:4 [ 0 => "Illuminate\Foundation\Application" 1 => "Illuminate\Contracts\Container\Container" 2 => "Illuminate\Contracts\Foundation\Application" 3 => "Psr\Container\ContainerInterface" ] "auth" => array:2 [ 0 => "Illuminate\Auth\AuthManager" 1 => "Illuminate\Contracts\Auth\Factory" ] "auth.driver" => array:1 [ 0 => "Illuminate\Contracts\Auth\Guard" ] "blade.compiler" => array:1 [ 0 => "Illuminate\View\Compilers\BladeCompiler" ] "cache" => array:2 [ 0 => "Illuminate\Cache\CacheManager" 1 => "Illuminate\Contracts\Cache\Factory" ] "cache.store" => array:3 [ 0 => "Illuminate\Cache\Repository" 1 => "Illuminate\Contracts\Cache\Repository" 2 => "Psr\SimpleCache\CacheInterface" ] "cache.psr6" => array:3 [ 0 => "Symfony\Component\Cache\Adapter\Psr16Adapter" 1 => "Symfony\Component\Cache\Adapter\AdapterInterface" 2 => "Psr\Cache\CacheItemPoolInterface" ] "config" => array:2 [ 0 => "Illuminate\Config\Repository" 1 => "Illuminate\Contracts\Config\Repository" ] "cookie" => array:3 [ 0 => "Illuminate\Cookie\CookieJar" 1 => "Illuminate\Contracts\Cookie\Factory" 2 => "Illuminate\Contracts\Cookie\QueueingFactory" ] "db" => array:2 [ 0 => "Illuminate\Database\DatabaseManager" 1 => "Illuminate\Database\ConnectionResolverInterface" ] "db.connection" => array:2 [ 0 => "Illuminate\Database\Connection" 1 => "Illuminate\Database\ConnectionInterface" ] "encrypter" => array:3 [ 0 => "Illuminate\Encryption\Encrypter" 1 => "Illuminate\Contracts\Encryption\Encrypter" 2 => "Illuminate\Contracts\Encryption\StringEncrypter" ] "events" => array:2 [ 0 => "Illuminate\Events\Dispatcher" 1 => "Illuminate\Contracts\Events\Dispatcher" ] "files" => array:1 [ 0 => "Illuminate\Filesystem\Filesystem" ] "filesystem" => array:2 [ 0 => "Illuminate\Filesystem\FilesystemManager" 1 => "Illuminate\Contracts\Filesystem\Factory" ] "filesystem.disk" => array:1 [ 0 => "Illuminate\Contracts\Filesystem\Filesystem" ] "filesystem.cloud" => array:1 [ 0 => "Illuminate\Contracts\Filesystem\Cloud" ] "hash" => array:1 [ 0 => "Illuminate\Hashing\HashManager" ] "hash.driver" => array:1 [ 0 => "Illuminate\Contracts\Hashing\Hasher" ] "translator" => array:2 [ 0 => "Illuminate\Translation\Translator" 1 => "Illuminate\Contracts\Translation\Translator" ] "log" => array:2 [ 0 => "Illuminate\Log\LogManager" 1 => "Psr\Log\LoggerInterface" ] "mail.manager" => array:2 [ 0 => "Illuminate\Mail\MailManager" 1 => "Illuminate\Contracts\Mail\Factory" ] "mailer" => array:3 [ 0 => "Illuminate\Mail\Mailer" 1 => "Illuminate\Contracts\Mail\Mailer" 2 => "Illuminate\Contracts\Mail\MailQueue" ] "auth.password" => array:2 [ 0 => "Illuminate\Auth\Passwords\PasswordBrokerManager" 1 => "Illuminate\Contracts\Auth\PasswordBrokerFactory" ] "auth.password.broker" => array:2 [ 0 => "Illuminate\Auth\Passwords\PasswordBroker" 1 => "Illuminate\Contracts\Auth\PasswordBroker" ] "queue" => array:3 [ 0 => "Illuminate\Queue\QueueManager" 1 => "Illuminate\Contracts\Queue\Factory" 2 => "Illuminate\Contracts\Queue\Monitor" ] "queue.connection" => array:1 [ 0 => "Illuminate\Contracts\Queue\Queue" ] "queue.failer" => array:1 [ 0 => "Illuminate\Queue\Failed\FailedJobProviderInterface" ] "redirect" => array:1 [ 0 => "Illuminate\Routing\Redirector" ] "redis" => array:2 [ 0 => "Illuminate\Redis\RedisManager" 1 => "Illuminate\Contracts\Redis\Factory" ] "redis.connection" => array:2 [ 0 => "Illuminate\Redis\Connections\Connection" 1 => "Illuminate\Contracts\Redis\Connection" ] "request" => array:2 [ 0 => "Illuminate\Http\Request" 1 => "Symfony\Component\HttpFoundation\Request" ] "router" => array:3 [ 0 => "Illuminate\Routing\Router" 1 => "Illuminate\Contracts\Routing\Registrar" 2 => "Illuminate\Contracts\Routing\BindingRegistrar" ] "session" => array:1 [ 0 => "Illuminate\Session\SessionManager" ] "session.store" => array:2 [ 0 => "Illuminate\Session\Store" 1 => "Illuminate\Contracts\Session\Session" ] "url" => array:2 [ 0 => "Illuminate\Routing\UrlGenerator" 1 => "Illuminate\Contracts\Routing\UrlGenerator" ] "validator" => array:2 [ 0 => "Illuminate\Validation\Factory" 1 => "Illuminate\Contracts\Validation\Factory" ] "view" => array:2 [ 0 => "Illuminate\View\Factory" 1 => "Illuminate\Contracts\View\Factory" ] ]