### Install Tracy with Composer Source: https://github.com/nette/docs/blob/master/tracy/tr/guide.texy This snippet demonstrates the recommended way to install the Tracy library using Composer, a dependency manager for PHP. Alternatively, you can download the `tracy.phar` file directly from the releases page. ```Shell composer require tracy/tracy ``` -------------------------------- ### Install Tracy with Composer Source: https://github.com/nette/docs/blob/master/tracy/pt/guide.texy This snippet demonstrates how to install the Tracy library using Composer, the most common dependency manager for PHP. Alternatively, you can download the complete package as a `tracy.phar` file. Ensure Composer is installed and accessible in your command line. ```Shell composer require tracy/tracy ``` -------------------------------- ### Install Tracy with Composer Source: https://github.com/nette/docs/blob/master/tracy/ru/guide.texy This snippet demonstrates how to install the Tracy library using Composer, the most common dependency manager for PHP. Ensure Composer is installed on your system before running this command. This command adds `tracy/tracy` to your project's `composer.json` and installs it into `vendor/`. ```Shell composer require tracy/tracy ``` -------------------------------- ### Install Tracy with Composer Source: https://github.com/nette/docs/blob/master/tracy/uk/guide.texy This snippet demonstrates how to install the Tracy debugging library using Composer, the PHP dependency manager. Composer simplifies the process of adding Tracy to your project by handling dependencies and autoloading, ensuring you get the latest stable version. ```shell composer require tracy/tracy ``` -------------------------------- ### Install Nette Tester with Composer Source: https://github.com/nette/docs/blob/master/tester/ro/guide.texy Provides the command to install Nette Tester as a development dependency using Composer, which is the preferred and recommended installation method. ```Terminal composer require --dev nette/tester ``` -------------------------------- ### Install Tracy with Composer Source: https://github.com/nette/docs/blob/master/tracy/es/guide.texy This snippet demonstrates how to install the Tracy debugging library using Composer, the PHP dependency manager. It ensures Tracy is added to your project's dependencies. ```Shell composer require tracy/tracy ``` -------------------------------- ### Install Nette Tracy with Composer Source: https://github.com/nette/docs/blob/master/tracy/it/guide.texy This snippet demonstrates the recommended way to install the Tracy library using Composer, the dependency manager for PHP. It ensures you get the latest stable package. ```Shell composer require tracy/tracy ``` -------------------------------- ### Installing Nette Tester via Composer Source: https://github.com/nette/docs/blob/master/tester/uk/guide.texy This command shows the preferred method for installing Nette Tester. Using Composer, the package is added as a development dependency, ensuring it's available for testing purposes without being included in production builds. ```terminal composer require --dev nette/tester ``` -------------------------------- ### Example Vite Entry Point (app.js) Source: https://github.com/nette/docs/blob/master/assets/tr/vite.texy An entry point is the main file where your application starts. This example shows how to import styles and JavaScript modules like `nette-forms` and `naja` into your `app.js`. ```javascript // Import styles import './style.css' // Import JavaScript modules import netteForms from 'nette-forms'; import naja from 'naja'; // Initialize your application netteForms.initOnLoad(); naja.initialize(); ``` -------------------------------- ### Verifying Nette Tester Installation from Command Line Source: https://github.com/nette/docs/blob/master/tester/ja/guide.texy This command checks if Nette Tester is correctly installed and accessible via its executable. Running `vendor/bin/tester` without parameters typically displays the help message, confirming the tool's presence and readiness for use. ```Terminal vendor/bin/tester ``` -------------------------------- ### Installing Nette Tester via Composer Source: https://github.com/nette/docs/blob/master/tester/ru/guide.texy This command demonstrates the preferred method for installing Nette Tester using Composer. The `--dev` flag indicates that Tester is a development dependency, meaning it's required for testing but not for the production application. This ensures proper project setup. ```terminal composer require --dev nette/tester ``` -------------------------------- ### Integrate Tracy with ProcessWire CMS/CMF Source: https://github.com/nette/docs/blob/master/tracy/uk/guide.texy This section covers integrating Tracy with ProcessWire. Integration usually involves installing a ProcessWire module that sets up Tracy, allowing developers to debug ProcessWire applications with Tracy's powerful features, including database query logging and variable inspection. ```APIDOC /** * ProcessWire Tracy Integration API * Reference: adrianbj/TracyDebugger */ class ProcessWireTracyModule { /** * Installs the Tracy Debugger module in ProcessWire. * This method sets up initial configuration and hooks. * @return void */ public function install(): void; /** * Initializes Tracy's debugger within the ProcessWire environment. * This typically involves setting up error handlers and adding ProcessWire-specific panels. * @param \ProcessWire\Wire $wire The ProcessWire Wire object. * @param array $options Configuration options for the debugger. * @return void */ public function init(\ProcessWire\Wire $wire, array $options = []): void; /** * Uninstalls the Tracy Debugger module, cleaning up any hooks or configurations. * @return void */ public function uninstall(): void; } ``` -------------------------------- ### Run Nette Tester from Command Line (Help) Source: https://github.com/nette/docs/blob/master/tester/ro/guide.texy Demonstrates how to invoke the Nette Tester executable from the command line without parameters, which displays the help message and available options. ```Terminal vendor/bin/tester ``` -------------------------------- ### Displaying Nette Tester Help Source: https://github.com/nette/docs/blob/master/tester/uk/guide.texy This command executes the Nette Tester binary without any parameters. When run this way, Nette Tester will display its help documentation, providing information on available commands and options. ```terminal vendor/bin/tester ``` -------------------------------- ### Install Nette Tester with Composer Source: https://github.com/nette/docs/blob/master/tester/hu/guide.texy This command provides the recommended way to install Nette Tester using Composer. It adds Nette Tester as a development dependency to your project, ensuring it's available for running tests without being included in production builds. ```Terminal composer require --dev nette/tester ``` -------------------------------- ### Installing Nette Tester via Composer Source: https://github.com/nette/docs/blob/master/tester/ja/guide.texy This command demonstrates the recommended way to install Nette Tester using Composer. The `--dev` flag ensures it's added as a development dependency, suitable for testing frameworks. This is the primary method for integrating Tester into a PHP project. ```Terminal composer require --dev nette/tester ``` -------------------------------- ### Implement setUp and tearDown Methods in PHP Tester TestCase Source: https://github.com/nette/docs/blob/master/tester/en/testcase.texy This example illustrates the use of `setUp()` and `tearDown()` methods within a Tester TestCase. `setUp()` is executed before each test method for preparation, and `tearDown()` is executed after each test method for cleanup. This ensures a consistent test environment. ```php use Tester\Assert; class NextTest extends Tester\TestCase { public function setUp() { # Preparation } public function tearDown() { # Clean-up } public function testOne() { Assert::same(/* ... */); } public function testTwo() { Assert::match(/* ... */); } } # Run test methods (new NextTest)->run(); ``` -------------------------------- ### Terminal: Install Nette Tester with Composer Source: https://github.com/nette/docs/blob/master/tester/en/guide.texy This terminal command shows the recommended way to install Nette Tester using Composer, adding it as a development dependency. Nette Tester requires PHP version 7.1 or higher for compatibility. ```Terminal composer require --dev nette/tester ``` -------------------------------- ### Install Latte Templating Engine with Composer Source: https://github.com/nette/docs/blob/master/latte/tr/develop.texy This snippet demonstrates how to install the Latte templating engine using Composer, the popular PHP dependency manager. It ensures you have the necessary libraries to start developing with Latte. The installation process is straightforward and integrates seamlessly with existing PHP projects. ```Shell composer require latte/latte ``` -------------------------------- ### Load Custom Setup Script with --setup Source: https://github.com/nette/docs/blob/master/tester/tr/running-tests.texy The --setup option allows Tester to load a specified PHP script at startup. This script can be used to customize the Tester runner, for example, by adding custom output handlers. The Tester\Runner\Runner $runner variable is available within this setup script for direct manipulation. ```APIDOC --setup ``` ```php $runner->outputHandlers[] = new MyOutputHandler; ``` ```terminal tester --setup tests/runner-setup.php tests ``` -------------------------------- ### Implement setUp and tearDown Methods in PHP Tester Source: https://github.com/nette/docs/blob/master/tester/uk/testcase.texy This example illustrates the use of `setUp()` and `tearDown()` methods within a `Tester\TestCase`. `setUp()` is executed before each test method for preparation, and `tearDown()` is executed after each test method for cleanup. It also clarifies the execution order and error handling behavior. ```PHP use Tester\Assert; class NextTest extends Tester\TestCase { public function setUp() { # Preparation } public function tearDown() { # Cleanup } public function testOne() { Assert::same(/* ... */); } public function testTwo() { Assert::match(/* ... */); } } # Running test methods (new NextTest)->run(); /* Method call order ----------------------- setUp() testOne() tearDown() setUp() testTwo() tearDown() */ ``` -------------------------------- ### Create Nette Web Project with Composer Source: https://github.com/nette/docs/blob/master/quickstart/it/@home.texy This command initializes a new Nette Framework web project in the specified directory (`nette-blog`). It downloads all necessary dependencies and sets up the basic application structure. ```shell composer create-project nette/web-project nette-blog ``` -------------------------------- ### Creating a Basic Nette Tester Assertion Source: https://github.com/nette/docs/blob/master/tester/uk/guide.texy This example shows how to write a simple test using Nette Tester's `Assert` class. It demonstrates initializing the Tester environment, asserting the count of an array, and checking for the presence of an element. Each assertion verifies that the actual value matches the expected value. ```php add(function ($request, $handler) { // This is a simplified representation. A real Tracy middleware // would integrate more deeply with Slim's error handling and services. Debugger::bar()->addPanel(new class implements Tracy\IBarPanel { public function getTab(): string { return 'Slim'; } public function getPanel(): string { return '

Slim App Info

Request URI: ' . $this->request->getUri() . '

'; } public function __construct() { $this->request = \Slim\Psr7\Factory\ServerRequestFactory::createFromGlobals(); } }); return $handler->handle($request); }); // Define routes $app->get('/', function ($request, $response, $args) { Debugger::bar()->addPanel(new Tracy\DumperPanel(['message' => 'Hello from Slim!'])); $response->getBody()->write('Hello world!'); return $response; }); $app->run(); ``` -------------------------------- ### SQL: Insert Sample Blog Posts Source: https://github.com/nette/docs/blob/master/quickstart/pl/home-page.texy This SQL snippet inserts three sample blog posts into the 'posts' table. It populates 'id', 'title', 'content', and 'created_at' fields with example data, useful for initial testing and development. ```SQL INSERT INTO `posts` (`id`, `title`, `content`, `created_at`) VALUES (1, 'Artykuł Pierwszy', 'Lorem ipsum dolor jeden', CURRENT_TIMESTAMP), (2, 'Artykuł Drugi', 'Lorem ipsum dolor dwa', CURRENT_TIMESTAMP), (3, 'Artykuł Trzeci', 'Lorem ipsum dolor trzy', CURRENT_TIMESTAMP); ``` -------------------------------- ### PHP Tester: TestCase with Setup and Teardown Source: https://github.com/nette/docs/blob/master/tester/hu/testcase.texy This example illustrates the implementation of setUp() and tearDown() methods within a Tester\TestCase. These methods are automatically invoked before and after each test method, respectively, for initialization and cleanup tasks. It also clarifies the execution order of these methods. ```PHP use Tester\Assert; class NextTest extends Tester\TestCase { public function setUp() { # Preparation } public function tearDown() { # Cleanup } public function testOne() { Assert::same(/* ... */); } public function testTwo() { Assert::match(/* ... */); } } # Run test methods (new NextTest)->run(); /* Method call order ------------------------ setUp() testOne() tearDown() setUp() testTwo() tearDown() */ ``` -------------------------------- ### Verify Nette Welcome Page in Browser Source: https://github.com/nette/docs/blob/master/quickstart/de/@home.texy After project creation, navigate to this URL in your web browser. This step confirms that the Nette Framework's default welcome page is displayed, indicating a successful initial setup of the web server and application. ```Text http://localhost/nette-blog/www/ ``` -------------------------------- ### Create a New Nette Project with Composer Source: https://github.com/nette/docs/blob/master/quickstart/de/@home.texy This command initializes a new Nette web project named 'nette-blog' using Composer. It sets up the basic directory structure and dependencies required to start developing your application. ```Shell composer create-project nette/web-project nette-blog ``` -------------------------------- ### Installing Nette Tester via Composer Source: https://github.com/nette/docs/blob/master/tester/cs/guide.texy This command demonstrates the preferred method for installing Nette Tester using Composer. The '--dev' flag indicates that Tester is a development dependency, meaning it's required for testing but not for the production application. ```terminal composer require --dev nette/tester ``` -------------------------------- ### SQL: Create Blog Posts Table Source: https://github.com/nette/docs/blob/master/quickstart/pl/home-page.texy This SQL snippet creates a 'posts' table in a MySQL database named 'quickstart'. It defines columns for 'id' (auto-increment primary key), 'title', 'content', and 'created_at'. The table uses the InnoDB engine for transactional support. ```SQL CREATE TABLE `posts` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `title` varchar(255) NOT NULL, `content` text NOT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB CHARSET=utf8; ``` -------------------------------- ### Insert Sample Data into 'posts' Table Source: https://github.com/nette/docs/blob/master/quickstart/ro/home-page.texy This SQL snippet inserts three example blog posts into the 'posts' table. It provides initial data for testing and demonstration purposes before implementing application-level data entry. ```SQL INSERT INTO `posts` (`id`, `title`, `content`, `created_at`) VALUES (1, 'Articolul Unu', 'Lorem ipusm dolor unu', CURRENT_TIMESTAMP), (2, 'Articolul Doi', 'Lorem ipsum dolor doi', CURRENT_TIMESTAMP), (3, 'Articolul Trei', 'Lorem ipsum dolor trei', CURRENT_TIMESTAMP); ``` -------------------------------- ### Initialize Nette Environment and Start Application Source: https://github.com/nette/docs/blob/master/application/it/how-it-works.texy This section outlines the initial steps for a Nette application, covering environment setup with Tracy for error logging and display, and the intelligent autodetect for development vs. production mode. It also describes how the Nette\Application\Application object is instantiated via the DI container and its run() method is called to begin processing HTTP requests. ```APIDOC 1. Environment Initialization: - Activate Tracy for logging/error display (production: logs, development: displays). - Nette autodetects development mode on localhost. - Details in [Bootstrap class|bootstrapping] chapter. 2. Application Startup: - HTTP request handling by Nette\Application\Application class. - Key objects created by **DI container** (DIC). - Obtain DIC via Configurator class. - DIC produces Application object. - Call Application->run() method to start. - This process occurs in [index.php |bootstrapping#index.php]. ``` -------------------------------- ### Install Nette/Utils and create basic HTML element Source: https://github.com/nette/docs/blob/master/utils/sl/html-elements.texy This snippet demonstrates how to install the `nette/utils` package via Composer and provides a basic example of creating an `` HTML element using `Nette\Utils\Html::el()`, setting its `src` attribute, and rendering it. It also shows the necessary `use` statement. ```Shell composer require nette/utils ``` ```PHP use Nette\Utils\Html; ``` ```PHP $el = Html::el('img'); // ustvari element $el->src = 'image.jpg'; // nastavi atribut src echo $el; // izpiše '' ``` -------------------------------- ### Nette PHP Web Application Entry Point (index.php) Source: https://github.com/nette/docs/blob/master/application/pt/bootstrapping.texy This PHP snippet illustrates the `index.php` file, which serves as the entry point for Nette web applications. It demonstrates how to instantiate the `Bootstrap` class, boot the web application to obtain the DI container, and then retrieve and run the `Nette\Application\Application` service to process incoming requests. ```PHP $bootstrap = new App\Bootstrap; // Inicialização do ambiente + criação do contêiner de DI $container = $bootstrap->bootWebApplication(); // O contêiner de DI cria o objeto Nette\Application\Application $application = $container->getByType(Nette\Application\Application::class); // Inicia a aplicação Nette e processa a requisição recebida $application->run(); ``` -------------------------------- ### Displaying Nette Tester Command Line Help Source: https://github.com/nette/docs/blob/master/tester/de/guide.texy This bash command executes the Nette Tester binary without any specific parameters. It typically outputs the help message, listing available commands, options, and usage instructions for the test runner, which is useful for understanding its capabilities. ```bash vendor/bin/tester ``` -------------------------------- ### Install Nette\Utils\Html and Basic Usage Source: https://github.com/nette/docs/blob/master/utils/de/html-elements.texy This snippet demonstrates how to install the `nette/utils` package via Composer and provides a basic example of creating and rendering an HTML image element. It also shows the required `use` alias for the `Nette\Utils\Html` class. ```shell composer require nette/utils ``` ```php use Nette\Utils\Html; ``` ```php $el = Html::el('img'); $el->src = 'image.jpg'; echo $el; ``` -------------------------------- ### Install Nette WebProject with Composer Source: https://github.com/nette/docs/blob/master/application/en/how-it-works.texy This command demonstrates how to quickly set up a new Nette WebProject application using Composer. It downloads all necessary dependencies and prepares the project for immediate use. Ensure Composer is installed and configured on your system before running this command. ```shell composer create-project nette/web-project ``` -------------------------------- ### Install Vite and Nette Plugin Source: https://github.com/nette/docs/blob/master/assets/tr/vite.texy This command installs Vite and the specific Nette plugin that helps Vite work perfectly with Nette projects. ```shell npm install -D vite @nette/vite-plugin ``` -------------------------------- ### Configure Server for Nette Pretty URLs Source: https://github.com/nette/docs/blob/master/nette/sl/troubleshooting.texy These snippets provide server configurations for enabling pretty URLs in Nette applications. The Apache example uses `mod_rewrite` in `.htaccess` to route requests to `index.php`, while the Nginx example uses `try_files` for similar functionality. Proper setup ensures clean, user-friendly URLs. ```apacheconf RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L] ``` ```nginx location / { try_files $uri $uri/ /index.php$is_args$args; # $is_args$args IS IMPORTANT! } ``` -------------------------------- ### Enable Tracy Debugger in WordPress Installations Source: https://github.com/nette/docs/blob/master/tracy/en/guide.texy This snippet shows how to integrate Tracy Debugger into a WordPress installation, often through a plugin like `ktstudio/WP-Tracy`. The integration typically involves activating the plugin and potentially adding configuration lines to `wp-config.php` or `functions.php` to control Tracy's behavior, such as enabling the Tracy Bar for administrators or setting the logging directory. ```PHP run(); ``` -------------------------------- ### Define Project Dependencies with Composer Source: https://github.com/nette/docs/blob/master/best-practices/pt/composer.texy To start using Composer, create a "composer.json" file at your project root to describe dependencies and metadata. After defining dependencies, run "composer update" to download them into the "vendor/" directory. This command also generates "composer.lock" with exact versions and "vendor/autoload.php" for easy library inclusion. ```json { "require": { "nette/database": "^3.0" } } ``` ```shell composer update ``` ```php require __DIR__ . '/vendor/autoload.php'; $db = new Nette\Database\Connection('sqlite::memory:'); ``` -------------------------------- ### Measure Single Code Block Execution Time with PHP Source: https://github.com/nette/docs/blob/master/tracy/en/stopwatch.texy This snippet demonstrates how to use `Debugger::timer()` to measure the elapsed time for a single operation. Call `Debugger::timer()` at the start and again at the end to get the duration in seconds. The example shows measuring a 2-second sleep operation. ```PHP Debugger::timer(); // sweet dreams my cherrie sleep(2); $elapsed = Debugger::timer(); // $elapsed = 2 ``` -------------------------------- ### NEON: Configure Database Connection in config/common.neon Source: https://github.com/nette/docs/blob/master/quickstart/ja/home-page.texy This NEON configuration snippet sets up the database connection parameters in 'config/common.neon'. It specifies the DSN for a MySQL database named 'quickstart' running on localhost, along with placeholders for the database username and password. Ensure correct indentation (spaces or tabs, but not mixed). ```NEON database: dsn: 'mysql:host=127.0.0.1;dbname=quickstart' user: *YOUR_USERNAME_HERE* password: *YOUR_DATABASE_PASSWORD_HERE* ``` -------------------------------- ### Writing a Basic Nette Tester Assertion Source: https://github.com/nette/docs/blob/master/tester/hu/guide.texy This example demonstrates how to create a self-checking test using Nette Tester. It initializes the Tester environment, performs operations on an array, and uses `Tester\Assert::same()` and `Tester\Assert::contains()` to verify expected outcomes, making the test automated and repeatable. ```PHP template->product = $this->repository->getProduct($id); } } ``` -------------------------------- ### Running a Nette Tester Script (Failure) Source: https://github.com/nette/docs/blob/master/tester/hu/guide.texy This example demonstrates the output when an assertion fails during the execution of a Nette Tester script. The terminal output clearly indicates the failure, showing the expected and actual values, along with the file and line number where the assertion failed, aiding in quick debugging. ```Terminal $ php ArrayTest.php Failed: ['foo'] should contain 'XXX' in ArrayTest.php(17) Assert::contains('XXX', $stack); FAILURE ``` -------------------------------- ### Example Vite Entry Point (app.js) Source: https://github.com/nette/docs/blob/master/assets/bg/vite.texy An entry point is the main file from which your application starts. From this file, you import other files (CSS, JavaScript modules, images), creating a dependency tree. Vite follows these imports and bundles everything together. ```JavaScript // Import styles import './style.css' // Import JavaScript modules import netteForms from 'nette-forms'; import naja from 'naja'; // Initialize your application netteForms.initOnLoad(); naja.initialize(); ``` -------------------------------- ### Nette Tester: Observing a Failed Test Execution Source: https://github.com/nette/docs/blob/master/tester/fr/guide.texy This example demonstrates the command-line output when a Nette Tester assertion fails. It clearly shows the expected vs. actual values, the file and line number of the failing assertion, and a 'FAILURE' status, aiding in quick debugging and identification of issues. ```terminal $ php ArrayTest.php Failed: ['foo'] should contain 'XXX' in ArrayTest.php(17) Assert::contains('XXX', $stack); FAILURE ``` -------------------------------- ### PHP: Initialize Nette Application Source: https://github.com/nette/docs/blob/master/tracy/en/@left-menu.texy Learn how to set up a basic Nette Framework application. This snippet demonstrates the minimal code required to bootstrap the application, including autoloader setup and dependency container creation. Requires Composer and PHP 7.4+. ```PHP enableTracy(__DIR__ . '/../log'); // Enable RobotLoader for automatic class loading $configurator->setTempDirectory(__DIR__ . '/../temp'); $configurator->createRobotLoader() ->addDirectory(__DIR__) ->register(); // Load configuration files $configurator->addConfig(__DIR__ . '/config/config.neon'); $container = $configurator->createContainer(); // Run the application (example for a simple presenter) $container->getByType(Nette\Application\Application::class)->run(); ``` -------------------------------- ### Nette DI Configuration: Expressions and Service Setup Source: https://github.com/nette/docs/blob/master/dependency-injection/ru/services.texy Demonstrates how to use expressions for parameters and service creation, and how to define setup calls within Nette DI configuration files. This allows for dynamic value resolution and post-creation initialization. ```NEON parameters: ipAddress: @http.request::getRemoteAddress() services: database: create: DatabaseFactory::create( @anotherService::getDsn() ) setup: - initialize( ::getenv('DB_USER') ) ``` -------------------------------- ### Enable Tracy Debugger in PHP Source: https://github.com/nette/docs/blob/master/tracy/ru/guide.texy This PHP snippet shows how to activate the Tracy Debugger. It's crucial to call `Debugger::enable()` as early as possible in your application, ideally before any output is sent to the browser. This ensures Tracy can intercept and display errors effectively. The example assumes Composer's autoloader is included. ```PHP use Tracy\\Debugger; require 'vendor/autoload.php'; // или tracy.phar Debugger::enable(); ``` -------------------------------- ### Run Nette Web Application from index.php Entry Point (PHP) Source: https://github.com/nette/docs/blob/master/application/ja/bootstrapping.texy This PHP snippet demonstrates the `index.php` file, which serves as the primary entry point for Nette web applications. It shows how to instantiate the `App\Bootstrap` class to initialize the environment and create the Dependency Injection (DI) container. Subsequently, it retrieves the `Nette\Application\Application` service from the container and executes the application to handle incoming web requests. ```PHP $bootstrap = new App\Bootstrap;\n// 環境の初期化 + DIコンテナの作成\n$container = $bootstrap->bootWebApplication();\n// DIコンテナは Nette\Application\Application オブジェクトを作成します\n$application = $container->getByType(Nette\Application\Application::class);\n// Netteアプリケーションを起動し、受信リクエストを処理します\n$application->run(); ``` -------------------------------- ### Integrate Tracy with Slim Framework Source: https://github.com/nette/docs/blob/master/tracy/uk/guide.texy This section outlines integrating Tracy with the Slim Framework. For Slim, Tracy is typically integrated as middleware or by registering it with Slim's dependency container, allowing it to intercept requests and provide debugging information for routes and application logic. ```APIDOC /** * Slim Framework Tracy Integration API * Reference: runcmf/runtracy */ class SlimTracyMiddleware { /** * Creates a new Tracy middleware instance for Slim applications. * @param array $config Configuration options for Tracy (e.g., log directory, email). * @return \Psr\Http\Server\MiddlewareInterface */ public function __construct(array $config = []): \Psr\Http\Server\MiddlewareInterface; /** * Processes an incoming server request and passes it to the next middleware or request handler. * Tracy's error handling and debugging features are active during this process. * @param \Psr\Http\Message\ServerRequestInterface $request The incoming request. * @param \Psr\Http\Server\RequestHandlerInterface $handler The next request handler. * @return \Psr\Http\Message\ResponseInterface */ public function process(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface; } ``` -------------------------------- ### Writing a Basic Nette Tester PHP Test Source: https://github.com/nette/docs/blob/master/tester/cs/guide.texy This example shows how to write a simple test using Nette Tester's Assert class. It demonstrates checking array count and content. Each Nette Tester test is a standalone PHP script that can be executed independently, simplifying debugging and verification. ```php table('book'); // 'book' is the table name foreach ($books as $book) { echo $book->title; // output 'title' column echo $book->author_id; // output 'author_id' column } ``` -------------------------------- ### Extend Setup for Modified Nette DI Services Source: https://github.com/nette/docs/blob/master/dependency-injection/pl/services.texy This example shows how to modify an existing service and also extend its setup phase. It demonstrates adding a new item to an array property (`$onStartup[]`) using a service reference and a method call. ```neon services: application.application: create: MyApplication alteration: true setup: - '$onStartup[]' = [@resource, init] ``` -------------------------------- ### Install Nette Utils and Basic HTML Element Creation Source: https://github.com/nette/docs/blob/master/utils/en/html-elements.texy This snippet demonstrates how to install the `nette/utils` package via Composer and provides a basic example of creating an `` HTML element using `Nette\Utils\Html::el()`. It shows setting an attribute and rendering the element, along with the necessary class alias. ```Shell composer require nette/utils ``` ```PHP use Nette\Utils\Html; ``` ```PHP $el = Html::el('img'); // creates element $el->src = 'image.jpg'; // sets src attribute echo $el; // prints '' ``` -------------------------------- ### Test Development Package Versions with Composer Source: https://github.com/nette/docs/blob/master/best-practices/it/composer.texy To test pre-release or development versions of packages, configure `composer.json` to allow minimum stability 'dev' while preferring stable versions. This setup enables installation of development builds when no stable alternative meets requirements, facilitating early testing of new features or fixes. ```json { "minimum-stability": "dev", "prefer-stable": true } ``` ```shell composer require nette/utils:4.0.x-dev ``` ```shell composer require nette/utils:4.0.0-RC2 ``` -------------------------------- ### Nette Application Bootstrapping and DI Container Usage Source: https://github.com/nette/docs/blob/master/application/fr/how-it-works.texy This snippet illustrates the typical entry point for a Nette application, showing how to initialize the environment, obtain the Dependency Injection (DI) container using `Configurator`, and launch the application by calling the `run()` method on the `Nette\Application\Application` object. It highlights Nette's smart autodetection for development vs. production mode. ```PHP createContainer(); // Get the Nette\Application\Application object from the container and run it $application = $container->getByType(Nette\Application\Application::class); $application->run(); ``` -------------------------------- ### Nette Tester: Displaying Command Line Help Source: https://github.com/nette/docs/blob/master/tester/fr/guide.texy Executing vendor/bin/tester without any parameters from the command line will display the help message for the Nette Tester runner. This is useful for quickly reviewing available commands and options. ```terminal vendor/bin/tester ``` -------------------------------- ### Nette Web Application Entry Point (index.php) Source: https://github.com/nette/docs/blob/master/application/sl/bootstrapping.texy This PHP snippet illustrates the `index.php` file, which serves as the primary entry point for Nette web applications. It orchestrates the application's startup by instantiating the `Bootstrap` class, initializing the environment and DI container, retrieving the `Application` service, and finally executing the application to handle incoming web requests. ```PHP $bootstrap = new App\Bootstrap; // Environment initialization + DI container creation $container = $bootstrap->bootWebApplication(); // The DI container creates the Nette\Application\Application object $application = $container->getByType(Nette\Application\Application::class); // Start the Nette application and process the incoming request $application->run(); ``` -------------------------------- ### Writing a Basic Nette Tester Assertion Script Source: https://github.com/nette/docs/blob/master/tester/ru/guide.texy This example demonstrates how to write a self-verifying test using Nette Tester. Each test is a standard PHP script that can be run independently. It uses `Tester\Assert` methods like `Assert::same()` and `Assert::contains()` to validate expected outcomes, ensuring the code behaves as intended. ```php