### Install Laravel.Aop via Composer Source: https://context7.com/ngmy/laravel.aop/llms.txt Installs the Laravel.Aop package using Composer and publishes its configuration file. This is the initial setup step for integrating AOP into a Laravel project. ```bash composer require ngmy/laravel.aop php artisan vendor:publish --provider="Ngmy\LaravelAop\ServiceProvider" ``` -------------------------------- ### Start AOP Watcher (Bash) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Starts the Laravel.Aop watcher service, which automatically recompiles AOP classes when file changes are detected. This is useful during development. ```bash php artisan aop:watch ``` -------------------------------- ### Manual Dump Autoload and Compile (Bash) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Demonstrates manually running Composer's dump-autoload command before compiling AOP classes. This is an alternative to the default behavior of `aop:compile`. ```bash composer dump-autoload php artisan aop:compile --no-dump-autoload ``` -------------------------------- ### Watch for Changes and Auto-Compile with Artisan Source: https://context7.com/ngmy/laravel.aop/llms.txt Starts a watcher process using the `aop:watch` Artisan command. This command monitors specified files and automatically recompiles AOP classes when changes are detected, which is particularly useful during development. ```bash # Start the watcher for auto-recompilation php artisan aop:watch ``` -------------------------------- ### Compile AOP Classes (Bash) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Compiles the Aspect-Oriented Programming classes for Laravel. This command should be run after making changes to attributes or interceptor configurations. ```bash php artisan aop:compile ``` -------------------------------- ### Get Message for Watch Event Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Factories-WatcherCallableFactory.html Constructs a descriptive message for a given watch event type and file path. This is useful for logging or user feedback. ```php private function getMessageForEvent(WatchEventType $type, string $path): string { // ... logic to format message ... } ``` -------------------------------- ### Load External Code Snippet with JavaScript Source: https://github.com/ngmy/laravel.aop/blob/master/docs/namespaces/ngmy-laravelaop-aspects-cache.html This JavaScript function loads external code snippets into a specified element. It fetches the code from a given URL, highlights it using Prism, and handles potential errors. It also manages modal interactions, including opening and closing modals and loading code snippets within them. This functionality is essential for displaying code examples within the documentation. ```javascript (function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre\[data-src\]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d\[0\].scrollTop = d\[0\].children\[1\].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(\`Modal with id "${trigger.dataset.modal}" could not be found\`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })(); ``` -------------------------------- ### Get Source Map from File - PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Services-SourceMapFileManager.html Retrieves the source map from a specified source map file. It takes a SourceMapFile object as input and returns a SourceMap object. This method is part of the SourceMapFileManager service. ```PHP public function get(SourceMapFile $sourceMapFile): SourceMap { // Method implementation to get source map } ``` -------------------------------- ### Configure Auto Compilation in composer.json (JSON) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Sets up a post-autoload-dump script in `composer.json` to automatically compile AOP classes after Composer's autoload files are generated. This ensures AOP classes are up-to-date. ```json { "scripts": { "post-autoload-dump": [ "Illuminate\Foundation\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi", "@php artisan aop:compile --no-dump-autoload --ansi" ] } } ``` -------------------------------- ### Register Attribute and Interceptor (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Configures the AOP interceptor mapping in Laravel's configuration. This example registers the 'Transactional' attribute to be handled by the 'TransactionalInterceptor'. ```php use App\Attributes\Transactional; use App\Interceptors\TransactionalInterceptor; use Ngmy\LaravelAop\Collections\InterceptMap; 'intercept' => InterceptMap::default()->merge([ Transactional::class => [ TransactionalInterceptor::class, ], ])->toArray() ``` -------------------------------- ### FlushAfterInterceptor Class Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Cache-Interceptors-FlushAfterInterceptor.html Documentation for the FlushAfterInterceptor class, which implements the MethodInterceptor interface. ```APIDOC ## Class FlushAfterInterceptor ### Description Represents an interceptor that performs an action after a method invocation, likely related to cache flushing. ### Implements * `MethodInterceptor` ### Methods #### invoke() ```php public invoke(MethodInvocation $invocation): mixed ``` ##### Description Executes the interceptor logic. This method is called when the intercepted method is invoked. ##### Parameters - **invocation** (`MethodInvocation`) - Required - The method invocation object containing details about the method call. ##### Returns - `mixed` - The result of the method invocation or the interceptor's processed result. ``` -------------------------------- ### CompileCommand API Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Commands-CompileCommand.html Details about the CompileCommand, including its signature, description, and the handle method. ```APIDOC ## CompileCommand API ### Description This section details the `CompileCommand` class, which is responsible for compiling AOP classes within a Laravel application. It outlines the command's signature, description, and the `handle` method's functionality and parameters. ### Method N/A (This is a console command, not a typical HTTP API endpoint) ### Endpoint N/A (Console command) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **int**: The exit code of the command. #### Response Example N/A ## CompileCommand Properties ### $description #### Description The console command description. #### Type `string` #### Default Value `'Compile the AOP classes'` ### $signature #### Description The name and signature of the console command. #### Type `string` #### Default Value `'aop:compile {--no-dump-autoload : Do not run the dump-autoload Composer command before compiling the AOP classes}'` ## CompileCommand Methods ### handle() #### Description Execute the console command. #### Parameters - **compiler** ([Compiler](classes/Ngmy-LaravelAop-Services-Compiler.html)) - Required - The AOP compiler instance. - **composer** (Composer) - Required - The Composer manager instance. #### Return Type `int` - The exit code of the command. ``` -------------------------------- ### Annotate Method with Transactional Attribute (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Applies the 'Transactional' attribute to a method. This indicates that the `createUser` method should be intercepted and executed within a database transaction. ```php $name]); } } ``` -------------------------------- ### Initialize Compiler Service in PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Services-Compiler.html Initializes a new instance of the Compiler service. It requires several dependencies, including compiled path, intercept map, aspect map factory, source map file, and source map file manager. ```PHP public __construct( CompiledPath $compiledPath, InterceptMap $interceptMap, AspectMapFactory $aspectMapFactory, SourceMapFile $sourceMapFile, SourceMapFileManager $sourceMapFileManager ): mixed ``` -------------------------------- ### Define Transactional Attribute (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Defines a custom attribute named 'Transactional' that can be applied to methods. This attribute is intended to mark methods for transactional behavior. ```php 'File created', WatchEventType::EVENT_TYPE_FILE_DELETED => 'File deleted', WatchEventType::EVENT_TYPE_FILE_UPDATED => 'File updated', default => 'Unknown event', }; } ``` -------------------------------- ### Initialize Panzoom for Scene Element Source: https://github.com/ngmy/laravel.aop/blob/master/docs/graphs/classes.html This JavaScript snippet demonstrates how to select an HTML element with the ID 'scene' and initialize the panzoom library on it. It configures panzoom with the option 'smoothScroll: false'. ```javascript var element = document.querySelector('#scene'); // And pass it to panzoom panzoom(element, { smoothScroll: false }) ``` -------------------------------- ### Define Transactional Interceptor (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/README.md Implements a MethodInterceptor for transactional operations. This interceptor uses Laravel's DB facade to wrap method invocations within a database transaction. ```php $invocation->proceed()); } } ``` -------------------------------- ### ServiceProvider Methods Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-ServiceProvider.html This section details the methods of the ServiceProvider class within the Ngmy\LaravelAop namespace. ```APIDOC ## ServiceProvider Methods ### Description Provides methods for registering and managing AOP functionality within a Laravel application. ### Methods #### boot() * **Description**: Initializes services or logic when the application boots. * **File**: `src/ServiceProvider.php` * **Line**: 44 * **Signature**: `public boot(): void` #### register() * **Description**: Registers services and bindings in the service container. * **File**: `src/ServiceProvider.php` * **Line**: 17 * **Signature**: `public register(): void` #### runInCompileCommand() * **Description**: Checks if the current process is running within the compile command. * **File**: `src/ServiceProvider.php` * **Line**: 63 * **Signature**: `private runInCompileCommand(): bool` * **Return Values**: * `bool`: True if the command is running in the compile command, false otherwise. #### runInWatchCommand() * **Description**: Checks if the current process is running within the watch command. * **File**: `src/ServiceProvider.php` * **Line**: 78 * **Signature**: `private runInWatchCommand(): bool` * **Return Values**: * `bool`: True if the command is running in the watch command, false otherwise. ``` -------------------------------- ### Construct SourceMapFile Object in PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-ValueObjects-SourceMapFile.html This snippet shows the constructor for the SourceMapFile class. It initializes a new instance of the class, optionally accepting a CompiledPath object as an argument. This is used to create a new SourceMapFile object. ```php public __construct([CompiledPath](classes/Ngmy-LaravelAop-ValueObjects-CompiledPath.html) $compiledPath) : mixed ``` -------------------------------- ### Load External Code Snippet in PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/files/src-aspects-transaction-interceptors-transactionalinterceptor.html This JavaScript code dynamically loads and displays PHP code snippets from external files within a modal. It uses XMLHttpRequest to fetch the code, Prism.js for syntax highlighting, and handles potential errors during the process. It also manages the modal's visibility and provides a warning if the page is opened locally. ```javascript (function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre\[data-src\]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d\[0\].scrollTop = d\[0\].children\[1\].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })(); ``` -------------------------------- ### WatchCommand API Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Commands-WatchCommand.html This section details the WatchCommand, including its signature, description, and the handle method. ```APIDOC ## POST /aop:watch ### Description This endpoint allows you to watch files and recompile AOP classes. It utilizes the WatchCommand from the Ngmy\LaravelAop\Commands namespace. ### Method POST ### Endpoint /aop:watch ### Parameters #### Query Parameters - **watcher** (Ngmy\LaravelAop\Services\Watcher) - Required - The watcher instance to be used for monitoring file changes. ### Request Example ```json { "watcher": "Ngmy\LaravelAop\Services\Watcher" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **message** (string) - A message detailing the result of the command execution. #### Response Example ```json { "status": "success", "message": "File watching and recompilation started successfully." } ``` ### Error Handling - **400 Bad Request**: If the watcher parameter is missing or invalid. - **500 Internal Server Error**: If an unexpected error occurs during the recompilation process. ``` -------------------------------- ### Get Exception Handler (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Logging-Interceptors-ExceptionLogLevelInterceptor.html The 'getExceptionHandler' method is a private method in ExceptionLogLevelInterceptor. It is responsible for retrieving the exception handler instance. This method returns an object of type 'Handler', which is used to manage how exceptions are processed within the AOP context. ```php private function getExceptionHandler(): Handler { // Implementation details for retrieving the exception handler // Example: return new DefaultExceptionHandler(); } ``` -------------------------------- ### CacheableInterceptor - invoke() Method Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Cache-Interceptors-CacheableInterceptor.html Details of the invoke method within the CacheableInterceptor class. ```APIDOC ## POST /ngmy/laravel.aop/invoke ### Description Handles the invocation of the CacheableInterceptor, processing method calls with caching logic. ### Method POST ### Endpoint /ngmy/laravel.aop/invoke ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **invocation** (MethodInvocation) - Required - The method invocation object to be processed. ### Request Example ```json { "invocation": { /* MethodInvocation object details */ } } ``` ### Response #### Success Response (200) - **mixed** - The result of the method invocation after applying caching logic. #### Response Example ```json { "result": "cached_or_computed_value" } ``` ``` -------------------------------- ### Initialize CSS Variables (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Collections-SourceMap.html This small JavaScript snippet calls the `cssVars` function, likely part of a library or framework, to initialize or process CSS variables. It's commonly used for dynamic styling, theming, or polyfilling CSS custom properties in older browsers. ```javascript cssVars({}); ``` -------------------------------- ### Constructor for WatcherCallableFactory Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Factories-WatcherCallableFactory.html Initializes a new instance of WatcherCallableFactory. It requires dependencies for exception handling, command execution, and view factory. ```php public function __construct(ExceptionHandler $exceptionHandler, Command $command, Factory $viewFactory) { // ... constructor logic ... } ``` -------------------------------- ### Dynamically Load Code Snippets and Manage Modals (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/files/src-aspects-retry-interceptors-retryonfailureinterceptor.html This JavaScript function handles the dynamic loading of external code snippets into `pre` elements using AJAX. It also manages the opening and closing of modal windows triggered by specific buttons, displaying the loaded code. It includes a warning for `file://` protocol limitations regarding XHR requests, which prevents source code viewing when opened locally. ```javascript (function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d[0].scrollTop = d[0].children[1].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error("Modal with id \""+trigger.dataset.modal+"\" could not be found"); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })(); ``` -------------------------------- ### Load External Code Snippet with XHR - JavaScript Source: https://github.com/ngmy/laravel.aop/blob/master/docs/files/src-collections-sourcemap.html Dynamically loads external code snippets via XMLHttpRequest and applies syntax highlighting using Prism. Handles file loading errors and supports line number highlighting. Includes modal functionality for viewing source code with fallback for local file protocol restrictions. ```javascript (function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line); code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d = document.getElementsByClassName("line-numbers"); d[0].scrollTop = d[0].children[1].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn('Viewing the source code is unavailable because you are opening this page from the file:// scheme; browsers block XHR requests when a page is opened this way'); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line); const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })(); ``` -------------------------------- ### Watcher Class Constructor Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Services-Watcher.html Initializes a new instance of the Watcher class. It takes an array of paths to monitor and an ExceptionHandler instance as dependencies. This method sets up the necessary properties for the Watcher to operate. ```php public function __construct(array $paths, ExceptionHandler $exceptionHandler) { $this->paths = $paths; $this->exceptionHandler = $exceptionHandler; } ``` -------------------------------- ### WatcherCallableFactory Constructor Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Factories-WatcherCallableFactory.html Creates a new instance of the WatcherCallableFactory. It requires an ExceptionHandler, a Command, and a Factory for views. ```APIDOC ## __construct WatcherCallableFactory ### Description Create a new instance of the WatcherCallableFactory. ### Method `public __construct(ExceptionHandler $exceptionHandler, Command $command, Factory $viewFactory)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "exceptionHandler": "ExceptionHandler object", "command": "Command object", "viewFactory": "Factory object" } ``` ### Response #### Success Response (200) N/A (Constructor) #### Response Example N/A (Constructor) ``` -------------------------------- ### Dynamically Load External Code Snippets and Handle Modals (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Collections-SourceMap.html This JavaScript IIFE (Immediately Invoked Function Expression) defines functions to dynamically load external code snippets into 'pre' tags using XHR requests and to manage modal windows. It handles displaying loaded code, error messages, and warns users if viewing from a 'file://' scheme, which blocks XHR requests. It also attaches event listeners for modal triggers and exit buttons. ```javascript (function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre\[data-src\]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line); code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d\[0\].scrollTop = d\[0\].children\[1\].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("\\[data-modal\\]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line); const exits = modal.querySelectorAll("\\[data-exit-button\\]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })(); ``` -------------------------------- ### Load External Code Snippet (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Logging-Attributes-ExceptionLogLevel.html This JavaScript function dynamically loads external code snippets into the DOM. It handles fetching code from a specified URL, supports line highlighting, and includes error handling for network requests. It's designed to work with Prism.js for syntax highlighting. ```javascript function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d[0].scrollTop = d[0].children[1].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } ``` -------------------------------- ### Handle Modal Interactions and Code Loading (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Logging-Attributes-ExceptionLogLevel.html This JavaScript code manages the behavior of modal dialogs, specifically for displaying source code. It prevents modals from opening when the page is loaded via the 'file://' scheme due to browser security restrictions. It also initializes the loading of external code snippets when modals are opened. ```javascript const modalButtons = document.querySelectorAll("["data-modal"] ``` -------------------------------- ### Define CompileCommand Description (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Commands-CompileCommand.html This snippet shows how to define the description for the CompileCommand in PHP. It sets a protected string property that describes the purpose of the console command. ```php protected string $description = 'Compile the AOP classes' ``` -------------------------------- ### runInWatchCommand Method Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-ServiceProvider.html Checks if the command is currently running in watch mode. ```APIDOC ## GET /ngmy/laravel.aop/runInWatchCommand ### Description This method returns a boolean value indicating whether the command is currently executing within a watch command context. This is useful for conditionally executing logic based on the runtime environment. ### Method GET ### Endpoint /ngmy/laravel.aop/runInWatchCommand ### Parameters #### Query Parameters None #### Request Body None ### Request Example ``` GET /ngmy/laravel.aop/runInWatchCommand ``` ### Response #### Success Response (200) - **return_value** (bool) - True if the command is running in the watch command, false otherwise. #### Response Example ```json { "return_value": true } ``` ``` -------------------------------- ### Initialize Modal Functionality (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Cache-Attributes-FlushAfter.html This JavaScript code initializes modal dialogs for displaying code snippets. It handles opening modals when specific buttons are clicked and closing them. It also includes a check to disable this functionality when the page is opened locally via the file:// scheme, as XHR requests are blocked in that context. ```javascript const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); ``` -------------------------------- ### Load External Code Snippet (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Exception-Attributes-LogLevel.html This JavaScript function loads external code snippets into preformatted HTML elements. It handles fetching code from a specified URL, supports line highlighting, and includes error handling for network requests. It's designed to work with the Prism.js library for syntax highlighting. ```javascript function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } ``` -------------------------------- ### Watcher Service API Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Services-Watcher.html Documentation for the Watcher service, including its constructor and the watch method for recompiling AOP classes. ```APIDOC ## Watcher Service API ### Description Documentation for the Watcher service, including its constructor and the watch method for recompiling AOP classes. ### Methods #### `__construct(array $paths, ExceptionHandler $exceptionHandler)` ##### Description Create a new instance of the Watcher service. ##### Parameters - **$paths** (array) - Required - The paths to watch. - **$exceptionHandler** (ExceptionHandler) - Required - The exception handler. #### `watch(Command $command, Factory $viewFactory)` ##### Description Watch the files and recompile the AOP classes. ##### Parameters - **$command** (Command) - Required - The command instance. - **$viewFactory** (Factory) - Required - The view factory instance. ### Properties #### `$exceptionHandler` - **Type**: ExceptionHandler - **Read-only**: true #### `$paths` - **Type**: array - **Read-only**: true ``` -------------------------------- ### Modal Button Event Listener and Initialization (JavaScript) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Retry-Attributes-RetryOnFailure.html This JavaScript code sets up event listeners for modal triggers and handles the logic for opening and closing modals. It also includes a check to disable modal functionality when the page is opened locally via the file:// protocol, as this can block necessary network requests. ```javascript const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); ``` -------------------------------- ### ClassLoader Constructor in PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Services-ClassLoader.html Initializes a new instance of the ClassLoader. It requires a CompiledPath object to be passed as an argument, which is then stored as a private, read-only property. ```PHP public function __construct(CompiledPath $compiledPath) { $this->compiledPath = $compiledPath; } ``` -------------------------------- ### Handle Method for CompileCommand (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Commands-CompileCommand.html This snippet illustrates the handle method for the CompileCommand in PHP. This method is responsible for executing the console command's logic, taking an AOP compiler and a Composer manager as dependencies. ```php public handle(Compiler $compiler, Composer $composer) : int ``` -------------------------------- ### Load External Code Snippet with JavaScript Source: https://github.com/ngmy/laravel.aop/blob/master/docs/files/src-services-classloader.html This JavaScript code fetches and displays code snippets from external files within a modal. It uses XMLHttpRequest to retrieve the code, Prism for syntax highlighting, and handles potential errors. It also includes logic to prevent functionality when the page is opened locally. ```javascript (function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre\[data-src\]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d\[0\].scrollTop = d\[0\].children\[1\].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })(); ``` -------------------------------- ### Define WatchCommand Description in PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Commands-WatchCommand.html This snippet defines the description for the 'aop:watch' console command in PHP. This description is displayed to the user when they ask for help with the command, explaining its purpose. It's crucial for user understanding and command discoverability. ```php protected string $description = 'Watch the files and recompile the AOP classes' ``` -------------------------------- ### Implement WatchCommand Handle Method in PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Commands-WatchCommand.html This snippet shows the implementation of the 'handle' method for the WatchCommand in PHP. This method contains the core logic that executes when the 'aop:watch' command is run. It utilizes a Watcher service to perform its task. ```php public handle(Watcher $watcher) : int { // Method logic here } ``` -------------------------------- ### Configure Auto-Compilation in composer.json Source: https://context7.com/ngmy/laravel.aop/llms.txt Sets up the `post-autoload-dump` script in `composer.json` to automatically compile AOP classes after Composer's autoload dump process. This ensures AOP classes are up-to-date during development. ```json { "scripts": { "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi", "@php artisan aop:compile --no-dump-autoload --ansi" ] } } ``` -------------------------------- ### Load External Code Snippet in PHP Source: https://github.com/ngmy/laravel.aop/blob/master/docs/files/src-aspects-exception-interceptors-loglevelinterceptor.html This JavaScript code snippet dynamically loads and displays PHP code snippets from external files within a modal window. It fetches the code using an XMLHttpRequest, handles potential errors, and highlights the code using Prism.js. It also includes logic to prevent execution when the page is opened locally. ```javascript (function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre\[data-src\]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })(); ``` -------------------------------- ### FlushAfter Attribute Constructor (PHP) Source: https://github.com/ngmy/laravel.aop/blob/master/docs/classes/Ngmy-LaravelAop-Aspects-Cache-Attributes-FlushAfter.html This snippet shows the constructor for the FlushAfter attribute in PHP. It allows developers to specify a cache key and an optional cache store to be used when flushing the cache after a method execution. The attribute targets methods. ```PHP public function __construct(string $key, ?string $store = null) { $this->key = $key; $this->store = $store; } ```