<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                這一章是最高級也是最重要的教程,但是本人不要求你馬上看明白,因為你們是初學者,等你們全學會了,再回來看,就明白很多了,里面很多內容都是初學都不能亂修改的,所以我建議初學者看看知道有這么一回事就行了,因為里面配置內容很多在多個章里面都有介紹說明的。 # 配置 系統容器是一個DI容器,包含應用程序運行所需的所有服務和參數。 很快你就能夠: 1、創建系統容器 2、使用NEON文件配置應用程序 3、處理生產和開發模式 4、創建和使用自己的容器擴展 系統容器是一個靜態依賴注入容器,它保存應用程序需要的所有服務和參數。 這意味著不僅是框架本身的服務,而是你決定使用的每個庫的服務。 看看這樣的系統容器的例子。 開發人員了解到,編寫容器是一件非常乏味的工作。 隨著應用程序的增長,管理應用程序肯定變得困難。 Nette會為你做的工作! 使用簡單的配置語言,我們將描述應用程序的服務,框架將生成PHP代碼。 在所有嚴重性 - 上面鏈接的容器也是這樣生成的。 # 配置器 代碼生成的任務是給Nette \ Configurator類。 編譯過程只被觸發一次,其結果被緩存。 為此,我們需要選擇一個目錄來存儲這個代碼。代碼在bootstrap.php文件里面。 ~~~ $configurator = new Nette\Configurator; $configurator->setTempDirectory(__DIR__ . '/../temp'); ~~~ 現在我們只是添加一個路徑到配置文件: ~~~ $configurator->addConfig(__DIR__ . '/config/config.neon'); ~~~ 獲取容器的實例是最簡單的: ~~~ // 返回SystemContainer實例 $container = $configurator->createContainer(); ~~~ 以上小節介紹bootstrap.php一些代碼內容。 # 環境 配置器嘗試檢測應用程序是否正在生產或開發服務器上運行。 只要客戶端的IP地址是127.0.0.1,服務器就會被認為是開發的。 如果我們不能找到使用哪個環境,但它不在乎,因為它只用于從配置文件加載部分。 我們可以通過addConfig()的第二個參數來定義它。 ~~~ $environment = Nette\Configurator::detectDebugMode('your ip address') ? $configurator::DEVELOPMENT : $configurator::PRODUCTION; $configurator->addConfig(__DIR__ . '/config/config.neon', $environment); ~~~ 我們可以通過$ environment傳遞任何字符串,不僅僅是生產或開發。 通過這個,我們可以要求Configurator加載配置文件的任何部分。 但是正確的檢測取決于你(例如,通過系統變量getenv('COMPUTERNAME')或服務器的主機名$ _SERVER ['SERVER_NAME'])。 # 開發模式 有點不同的是應用程序運行模式。 我們可以作為開發人員訪問生產服務器,我們希望激活Tracy調試器。 運行模式通過與上述環境相同的原理,根據客戶端的IP地址區分。 我們通過isDebugMode()獲取模式,并通過setDebugMode()設置模式。 當我們通過enableDebugger()啟用調試器時很有用,它必須放在模式設置之后。 ~~~ // 激活列出的IP地址的Tracy調試器 $configurator->setDebugMode(['90.180.45.360', '90.180.45.361']); // 或任何人 $configurator->setDebugMode(); // = TRUE // 或沒有人 $configurator->setDebugMode($configurator::NONE); // = FALSE $configurator->enableDebugger(__DIR__ . '/../log'); ~~~ # 類自動加載 要編譯容器,Configurator需要加載配置文件中提到的所有類。 它是方便的自動加載在您的處置和Configurator提供一個方法創建一個RobotLoader的實例。 我們只添加希望被索引的目錄并激活裝載器。 不要忘記在調用createContainer()之前放置此代碼。 ~~~ $configurator->createRobotLoader() ->addDirectory(__DIR__) ->register(); ~~~ # 框架配置 配置通常以NEON格式編寫。 有樂趣嘗試的語法在http://ne-on.org。 Nette Framework的許多功能可以在配置文件中設置。 # HTTP代理 您可以定義http代理,使HTTP請求的遠程地址和遠程主機正確。這文件配置在config.neon。 ~~~ http: proxy: 127.0.0.1 # ip address, range, hostname or array of these values ~~~ # Sessions 在這里你可以設置所有指令(camelCase格式)。 ~~~ session: autoStart: true # default is smart expiration: 10 days name: ... ... ~~~ autoStart:smart。 僅當會話已存在時,它才自動啟動會話。 以后還會說明SESSIONS內容。 # Application ~~~ application: debugger: true # debugger bar panel catchExceptions: %productionMode% errorPresenter: Front:Error mapping: # mapping between presenter name and presenter class Front: App\*Module\*Presenter ~~~ # Routing ~~~ routing: debugger: true # debugger bar panel routes: index.php: Dashboard:default '<presenter>/<action>[/<id>]': Dashboard:default ~~~ # 安全 ~~~ security: debugger: true # debugger bar panel users: johndoe: secretpassword roles: guest: member: admin: [member] # admin extends member resources: file: ~~~ 通過填寫用戶選項,您創建SimpleAuthenticator,通過定義角色或資源創建Nette \ Security \ Permission授權者。 # HTTP headers ~~~ http: frames: ... # ovlivňuje hlavi?ku X-Frame-Options ~~~ 出于安全原因,Nette框架默認發送HTTP頭X-Frame-Options:SAMEORIGIN,以便頁面可以嵌入在僅來自同一域上的頁面的iframe中。 這種行為在某些情況下可能是不需要的(例如,如果你正在開發一個Facebook應用程序)。 您可以通過框架覆蓋此設置:yes,frames:http://allowed-host.com或frames:no。 # Mailing 默認郵件程序是SendmailMailer。 通過設置smtp,您可以激活SmtpMailer。 ~~~ mail: smtp: true # use SmtpMailer instead of SendmailMailer # optional settings host: ... port: ... username: ... password: ... secure: # possible values are ssl, tls or null timeout: ... ~~~ # Database 您可以定義多個數據庫連接,如果這樣做,您可以設置哪一個將自動注入您的服務通過autowired選項。 以下代碼顯示如何設置一個名為default的連接。 ~~~ database: default: dsn: "sqlite2:%appDir%/models/demo.db" user: ... password: ... options: [PDO::MYSQL_ATTR_COMPRESS = true] debugger: false # debugger bar panel explain: false # explain queries in debugger bar reflection: discovered # or static or classname, default is discovered autowired: true ~~~ 這將創建service @ nette.database.default并為您設置反射和緩存。 # Forms 您可以更改默認驗證錯誤消息。 ~~~ forms: messages: EQUAL: 'Please enter %s.' FILLED: 'Please complete mandatory field.' MIN_LENGTH: 'Please enter a value of at least %d characters.' EMAIL: '%label must be valid e-mail' ~~~ # Latte 您可以打開和關閉XHTML呈現模式并注冊自定義宏。 自定義宏可以作為類名稱或作為服務引用傳遞。 默認的調用方法是install,您可以通過附加雙冒號和自定義方法名稱來更改它。 ~~~ latte: xhtml: yes # default is no macros: - App\MyLatteMacros::register # static method, classname or callable - @App\MyLatteMacrosFactory # service with install method - @App\MyLatteMacrosFactory::register # service with register method services: - App\MyLatteMacrosFactory ~~~ # DI container ~~~ di: debugger: true #debugger bar panel accessors: true #enables $container->serviceName shortcut ~~~ # Tracy debugger ~~~ tracy: email: webmaster@example.com # for sending error logs strictMode: TRUE editor: ... browser: ... bar: # debugger bar panels - Nette\Bridges\DITracy\ContainerPanel # alias of DI container bar - IncludePanel - XDebugHelper('myIdeKey') - MyPanel(@MyService) blueScreen: # blue screen panels - DoctrinePanel::renderException ~~~ # Low-level modifications 所有這些設置影響最終的DI容器。 與服務部分中的直接定義相比,它提供了更短和更直接的語法。 如果您需要自己調整這些服務,您可以重新定義它們: ~~~ services: mail.mailer: class: MySmtpMailer application.presenterFactory: class: MyPresenterFactory ~~~ 或創建擴展默認服務的新服務: ~~~ services: myConnection < nette.database.default: setup: $onQuery: [ @logger::log ] ~~~ # 自定義服務 **服務定義** ~~~ services: database: Nette\Database\Connection(%dsn%, %user%, %password%) # or multi-lines database: factory: Nette\Database\Connection(%dsn%, %user%, %password%) # or more multi-lines :-) database: class: Nette\Database\Connection arguments: [%dsn%, %user%, %password%] ~~~ 生成: ~~~ function createServiceDatabase() { return new Nette\Database\Connection( $this->parameters['dsn'], $this->parameters['user'], $this->parameters['password'] ); } ~~~ 服務定義: ~~~ services: database: class: Nette\Database\Connection factory: DbFactory::createConnection ~~~ DbFactory::createConnection: ~~~ class DbFactory { static function createConnection(Nette\DI\Container $container) { ... } } ~~~ Generates: ~~~ function createServiceDatabase() { return DbFactory::createConnection($this); } ~~~ # Setup ~~~ services: database: class: Nette\Database\Connection(%dsn%, %user%, %password%) setup: - setCacheStorage(@cacheStorage) ~~~ Generates: ~~~ function createServiceDatabase() { $service = new Nette\Database\Connection(...); $service->setCacheStorage($this->cacheStorage); return $service; } ~~~ 自動裝配功能自動添加依賴項,因此甚至不必提及它們: ~~~ setup: - setCacheStorage ~~~ 在cacheStorage服務不存在的情況下,可以使用調用的結果作為參數: ~~~ setup: - setCacheStorage( Factory::createStorage() ) # or a method of other service: - setCacheStorage( @factory::createStorage() ) ~~~ 或者,新創建的類實例: ~~~ setup: - setCacheStorage( Nette\Caching\Storages\FileStorage(%tempDir%) ) # generates: $service->setCacheStorage(new Nette\Caching\Storages\FileStorage(...)); ~~~ 您還可以設置屬性的值: 替換 ~~~ setup: - $substitutions( [db: test] ) # generates: $service->substitutions = ['db' => 'test']; ~~~ 完整示例: ~~~ parameters: database: driver: mysql host: localhost dbname: test user: jim password: beam substitutions: db: test services: database: class: Nette\Database\Connection( '%database.driver%:host=%database.host%;dbname=%database.dbname%', %database.user%, %database.password%, null, Nette\Database\Reflection\DiscoveredReflection() ) setup: - setCacheStorage - $substitutions( %database.substitutions% ) ~~~ # 匿名服務 之后的時間有一些服務,實際上沒有在配置文件中的任何其他地方引用。 在這種情況下命名這些服務不是必需的。 要定義匿名服務,請使用以下語法: ~~~ services: - Simple\Service - class: Complex\Service setup: - setLang(%lang%) ~~~ 要引用這樣的匿名服務,您將需要使用完全限定類名稱。 ~~~ services: router: @App\RouterFactory::createRouter ~~~ 請記住,從匿名服務的性質,不可能注冊多個相同類型,因為它會導致歧義。 # 服務定義繼承 ~~~ services: dev_database < database setup: - Diagnostics\ConnectionPanel::initialize ~~~ # Auto-wiring 自動布線功能可以自動將依賴傳遞到服務的構造函數和方法。 它使用typehinting和@return注釋。 只有一個服務匹配容器中的類型,否則拋出異常。 要定義多個相同類型的服務,我們需要將它們從自動布線中排除: ~~~ services: cacheStorage: class: Nette\Caching\Storages\FileStorage(%tempDir%) tempCacheStorage: class: Nette\Caching\Storages\DevNullStorage autowired: no ~~~ 當修改Nette Framework的核心服務時,我們需要確保容器知道我們想要使用的類。 這意味著在@return注釋中使用完全限定類名或者用類條目設置FQ類名。 # 多個配置文件 使用includes部分添加更多配置文件。 ~~~ includes: - parameters.php - services.neon - presenters.neon ~~~ 配置合并過程將包含包含部分和最低優先級的文件的最高優先級分配給第一個包含的文件。 要防止合并某個數組,請在數組名稱后面使用感嘆號: ~~~ argument!: [1, 2, 3] ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看