======================== CODE SNIPPETS ======================== TITLE: Install Tracy with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/tr/guide.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require tracy/tracy ``` ---------------------------------------- TITLE: Install Tracy with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/pt/guide.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require tracy/tracy ``` ---------------------------------------- TITLE: Install Tracy with Composer DESCRIPTION: 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/`. SOURCE: https://github.com/nette/docs/blob/master/tracy/ru/guide.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require tracy/tracy ``` ---------------------------------------- TITLE: Install Tracy with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/uk/guide.texy#_snippet_0 LANGUAGE: shell CODE: ``` composer require tracy/tracy ``` ---------------------------------------- TITLE: Install Nette Tester with Composer DESCRIPTION: Provides the command to install Nette Tester as a development dependency using Composer, which is the preferred and recommended installation method. SOURCE: https://github.com/nette/docs/blob/master/tester/ro/guide.texy#_snippet_4 LANGUAGE: Terminal CODE: ``` composer require --dev nette/tester ``` ---------------------------------------- TITLE: Install Tracy with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/es/guide.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require tracy/tracy ``` ---------------------------------------- TITLE: Install Nette Tracy with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/it/guide.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require tracy/tracy ``` ---------------------------------------- TITLE: Installing Nette Tester via Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/uk/guide.texy#_snippet_4 LANGUAGE: terminal CODE: ``` composer require --dev nette/tester ``` ---------------------------------------- TITLE: Example Vite Entry Point (app.js) DESCRIPTION: 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`. SOURCE: https://github.com/nette/docs/blob/master/assets/tr/vite.texy#_snippet_6 LANGUAGE: javascript CODE: ``` // Import styles import './style.css' // Import JavaScript modules import netteForms from 'nette-forms'; import naja from 'naja'; // Initialize your application netteForms.initOnLoad(); naja.initialize(); ``` ---------------------------------------- TITLE: Verifying Nette Tester Installation from Command Line DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/ja/guide.texy#_snippet_5 LANGUAGE: Terminal CODE: ``` vendor/bin/tester ``` ---------------------------------------- TITLE: Installing Nette Tester via Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/ru/guide.texy#_snippet_4 LANGUAGE: terminal CODE: ``` composer require --dev nette/tester ``` ---------------------------------------- TITLE: Integrate Tracy with ProcessWire CMS/CMF DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/uk/guide.texy#_snippet_6 LANGUAGE: APIDOC CODE: ``` /** * 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; } ``` ---------------------------------------- TITLE: Run Nette Tester from Command Line (Help) DESCRIPTION: Demonstrates how to invoke the Nette Tester executable from the command line without parameters, which displays the help message and available options. SOURCE: https://github.com/nette/docs/blob/master/tester/ro/guide.texy#_snippet_5 LANGUAGE: Terminal CODE: ``` vendor/bin/tester ``` ---------------------------------------- TITLE: Displaying Nette Tester Help DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/uk/guide.texy#_snippet_5 LANGUAGE: terminal CODE: ``` vendor/bin/tester ``` ---------------------------------------- TITLE: Install Nette Tester with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/hu/guide.texy#_snippet_4 LANGUAGE: Terminal CODE: ``` composer require --dev nette/tester ``` ---------------------------------------- TITLE: Installing Nette Tester via Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/ja/guide.texy#_snippet_4 LANGUAGE: Terminal CODE: ``` composer require --dev nette/tester ``` ---------------------------------------- TITLE: Implement setUp and tearDown Methods in PHP Tester TestCase DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/en/testcase.texy#_snippet_1 LANGUAGE: php CODE: ``` 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(); ``` ---------------------------------------- TITLE: Terminal: Install Nette Tester with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/en/guide.texy#_snippet_4 LANGUAGE: Terminal CODE: ``` composer require --dev nette/tester ``` ---------------------------------------- TITLE: Install Latte Templating Engine with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/latte/tr/develop.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require latte/latte ``` ---------------------------------------- TITLE: Load Custom Setup Script with --setup DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/tr/running-tests.texy#_snippet_3 LANGUAGE: APIDOC CODE: ``` --setup ``` LANGUAGE: php CODE: ``` $runner->outputHandlers[] = new MyOutputHandler; ``` LANGUAGE: terminal CODE: ``` tester --setup tests/runner-setup.php tests ``` ---------------------------------------- TITLE: Implement setUp and tearDown Methods in PHP Tester DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/uk/testcase.texy#_snippet_1 LANGUAGE: PHP CODE: ``` 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() */ ``` ---------------------------------------- TITLE: Create Nette Web Project with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/quickstart/it/@home.texy#_snippet_0 LANGUAGE: shell CODE: ``` composer create-project nette/web-project nette-blog ``` ---------------------------------------- TITLE: Creating a Basic Nette Tester Assertion DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/uk/guide.texy#_snippet_1 LANGUAGE: php CODE: ``` 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(); ``` ---------------------------------------- TITLE: SQL: Insert Sample Blog Posts DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/quickstart/pl/home-page.texy#_snippet_1 LANGUAGE: SQL CODE: ``` 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); ``` ---------------------------------------- TITLE: PHP Tester: TestCase with Setup and Teardown DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/hu/testcase.texy#_snippet_1 LANGUAGE: PHP CODE: ``` 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() */ ``` ---------------------------------------- TITLE: Verify Nette Welcome Page in Browser DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/quickstart/de/@home.texy#_snippet_1 LANGUAGE: Text CODE: ``` http://localhost/nette-blog/www/ ``` ---------------------------------------- TITLE: Create a New Nette Project with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/quickstart/de/@home.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer create-project nette/web-project nette-blog ``` ---------------------------------------- TITLE: Installing Nette Tester via Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/cs/guide.texy#_snippet_4 LANGUAGE: terminal CODE: ``` composer require --dev nette/tester ``` ---------------------------------------- TITLE: SQL: Create Blog Posts Table DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/quickstart/pl/home-page.texy#_snippet_0 LANGUAGE: SQL CODE: ``` 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; ``` ---------------------------------------- TITLE: Insert Sample Data into 'posts' Table DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/quickstart/ro/home-page.texy#_snippet_1 LANGUAGE: SQL CODE: ``` 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); ``` ---------------------------------------- TITLE: Initialize Nette Environment and Start Application DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/application/it/how-it-works.texy#_snippet_0 LANGUAGE: APIDOC CODE: ``` 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]. ``` ---------------------------------------- TITLE: Install Nette/Utils and create basic HTML element DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/utils/sl/html-elements.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require nette/utils ``` LANGUAGE: PHP CODE: ``` use Nette\Utils\Html; ``` LANGUAGE: PHP CODE: ``` $el = Html::el('img'); // ustvari element $el->src = 'image.jpg'; // nastavi atribut src echo $el; // izpiše '' ``` ---------------------------------------- TITLE: Nette PHP Web Application Entry Point (index.php) DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/application/pt/bootstrapping.texy#_snippet_1 LANGUAGE: PHP CODE: ``` $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(); ``` ---------------------------------------- TITLE: Displaying Nette Tester Command Line Help DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/de/guide.texy#_snippet_5 LANGUAGE: bash CODE: ``` vendor/bin/tester ``` ---------------------------------------- TITLE: Install Nette\Utils\Html and Basic Usage DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/utils/de/html-elements.texy#_snippet_0 LANGUAGE: shell CODE: ``` composer require nette/utils ``` LANGUAGE: php CODE: ``` use Nette\Utils\Html; ``` LANGUAGE: php CODE: ``` $el = Html::el('img'); $el->src = 'image.jpg'; echo $el; ``` ---------------------------------------- TITLE: Install Nette WebProject with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/application/en/how-it-works.texy#_snippet_1 LANGUAGE: shell CODE: ``` composer create-project nette/web-project ``` ---------------------------------------- TITLE: Install Vite and Nette Plugin DESCRIPTION: This command installs Vite and the specific Nette plugin that helps Vite work perfectly with Nette projects. SOURCE: https://github.com/nette/docs/blob/master/assets/tr/vite.texy#_snippet_0 LANGUAGE: shell CODE: ``` npm install -D vite @nette/vite-plugin ``` ---------------------------------------- TITLE: Configure Server for Nette Pretty URLs DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/nette/sl/troubleshooting.texy#_snippet_1 LANGUAGE: apacheconf CODE: ``` 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] ``` LANGUAGE: nginx CODE: ``` location / { try_files $uri $uri/ /index.php$is_args$args; # $is_args$args IS IMPORTANT! } ``` ---------------------------------------- TITLE: Enable Tracy Debugger in WordPress Installations DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/en/guide.texy#_snippet_9 LANGUAGE: PHP CODE: ``` run(); ``` ---------------------------------------- TITLE: Define Project Dependencies with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/best-practices/pt/composer.texy#_snippet_1 LANGUAGE: json CODE: ``` { "require": { "nette/database": "^3.0" } } ``` LANGUAGE: shell CODE: ``` composer update ``` LANGUAGE: php CODE: ``` require __DIR__ . '/vendor/autoload.php'; $db = new Nette\Database\Connection('sqlite::memory:'); ``` ---------------------------------------- TITLE: Measure Single Code Block Execution Time with PHP DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/en/stopwatch.texy#_snippet_0 LANGUAGE: PHP CODE: ``` Debugger::timer(); // sweet dreams my cherrie sleep(2); $elapsed = Debugger::timer(); // $elapsed = 2 ``` ---------------------------------------- TITLE: NEON: Configure Database Connection in config/common.neon DESCRIPTION: 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). SOURCE: https://github.com/nette/docs/blob/master/quickstart/ja/home-page.texy#_snippet_2 LANGUAGE: NEON CODE: ``` database: dsn: 'mysql:host=127.0.0.1;dbname=quickstart' user: *YOUR_USERNAME_HERE* password: *YOUR_DATABASE_PASSWORD_HERE* ``` ---------------------------------------- TITLE: Writing a Basic Nette Tester Assertion DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/hu/guide.texy#_snippet_1 LANGUAGE: PHP CODE: ``` template->product = $this->repository->getProduct($id); } } ``` ---------------------------------------- TITLE: Running a Nette Tester Script (Failure) DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/hu/guide.texy#_snippet_3 LANGUAGE: Terminal CODE: ``` $ php ArrayTest.php Failed: ['foo'] should contain 'XXX' in ArrayTest.php(17) Assert::contains('XXX', $stack); FAILURE ``` ---------------------------------------- TITLE: Example Vite Entry Point (app.js) DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/assets/bg/vite.texy#_snippet_6 LANGUAGE: JavaScript CODE: ``` // Import styles import './style.css' // Import JavaScript modules import netteForms from 'nette-forms'; import naja from 'naja'; // Initialize your application netteForms.initOnLoad(); naja.initialize(); ``` ---------------------------------------- TITLE: Nette Tester: Observing a Failed Test Execution DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/fr/guide.texy#_snippet_3 LANGUAGE: terminal CODE: ``` $ php ArrayTest.php Failed: ['foo'] should contain 'XXX' in ArrayTest.php(17) Assert::contains('XXX', $stack); FAILURE ``` ---------------------------------------- TITLE: PHP: Initialize Nette Application DESCRIPTION: 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+. SOURCE: https://github.com/nette/docs/blob/master/tracy/en/@left-menu.texy#_snippet_0 LANGUAGE: PHP CODE: ``` 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(); ``` ---------------------------------------- TITLE: Nette DI Configuration: Expressions and Service Setup DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/dependency-injection/ru/services.texy#_snippet_0 LANGUAGE: NEON CODE: ``` parameters: ipAddress: @http.request::getRemoteAddress() services: database: create: DatabaseFactory::create( @anotherService::getDsn() ) setup: - initialize( ::getenv('DB_USER') ) ``` ---------------------------------------- TITLE: Enable Tracy Debugger in PHP DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/ru/guide.texy#_snippet_1 LANGUAGE: PHP CODE: ``` use Tracy\\Debugger; require 'vendor/autoload.php'; // или tracy.phar Debugger::enable(); ``` ---------------------------------------- TITLE: Run Nette Web Application from index.php Entry Point (PHP) DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/application/ja/bootstrapping.texy#_snippet_1 LANGUAGE: PHP CODE: ``` $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(); ``` ---------------------------------------- TITLE: Integrate Tracy with Slim Framework DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tracy/uk/guide.texy#_snippet_7 LANGUAGE: APIDOC CODE: ``` /** * 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; } ``` ---------------------------------------- TITLE: Writing a Basic Nette Tester PHP Test DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/cs/guide.texy#_snippet_1 LANGUAGE: php CODE: ``` 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 } ``` ---------------------------------------- TITLE: Extend Setup for Modified Nette DI Services DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/dependency-injection/pl/services.texy#_snippet_25 LANGUAGE: neon CODE: ``` services: application.application: create: MyApplication alteration: true setup: - '$onStartup[]' = [@resource, init] ``` ---------------------------------------- TITLE: Install Nette Utils and Basic HTML Element Creation DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/utils/en/html-elements.texy#_snippet_0 LANGUAGE: Shell CODE: ``` composer require nette/utils ``` LANGUAGE: PHP CODE: ``` use Nette\Utils\Html; ``` LANGUAGE: PHP CODE: ``` $el = Html::el('img'); // creates element $el->src = 'image.jpg'; // sets src attribute echo $el; // prints '' ``` ---------------------------------------- TITLE: Test Development Package Versions with Composer DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/best-practices/it/composer.texy#_snippet_5 LANGUAGE: json CODE: ``` { "minimum-stability": "dev", "prefer-stable": true } ``` LANGUAGE: shell CODE: ``` composer require nette/utils:4.0.x-dev ``` LANGUAGE: shell CODE: ``` composer require nette/utils:4.0.0-RC2 ``` ---------------------------------------- TITLE: Nette Application Bootstrapping and DI Container Usage DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/application/fr/how-it-works.texy#_snippet_0 LANGUAGE: PHP CODE: ``` createContainer(); // Get the Nette\Application\Application object from the container and run it $application = $container->getByType(Nette\Application\Application::class); $application->run(); ``` ---------------------------------------- TITLE: Nette Tester: Displaying Command Line Help DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/fr/guide.texy#_snippet_5 LANGUAGE: terminal CODE: ``` vendor/bin/tester ``` ---------------------------------------- TITLE: Nette Web Application Entry Point (index.php) DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/application/sl/bootstrapping.texy#_snippet_1 LANGUAGE: PHP CODE: ``` $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(); ``` ---------------------------------------- TITLE: Writing a Basic Nette Tester Assertion Script DESCRIPTION: 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. SOURCE: https://github.com/nette/docs/blob/master/tester/ru/guide.texy#_snippet_1 LANGUAGE: php CODE: ```