Download the PHP package scriptua/magento2-base without Composer
On this page you can find all versions of the php package scriptua/magento2-base. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package magento2-base
Magento 2 Base Module
A comprehensive Magento 2 base module providing:
- Yii2 Framework Helpers: Battle-tested utility classes for array manipulation, HTML generation, JSON handling, and debugging
- ViewModel Registry: Global access to view models in templates without layout XML configuration
- Console Utilities: ANSI terminal control, progress bars, and formatted CLI output
- Layout Debugging: Developer mode tools for layout XML and block structure inspection
Installation Guide
Table of Contents
- Core Features
- ViewModel Registry
- Layout Debugging
- Extensible Admin Menu
- Yii2 Framework Helpers
- ArrayHelper
- Html
- Json
- VarDumper
- Console Utilities
- Requirements
- License
Core Features
1. ViewModel Registry ($viewModels)
Access any view model directly in templates without declaring them in layout XML. The $viewModels variable is automatically available in all .phtml templates.
Usage in templates:
How it works:
- Automatically injected into all PHP template engines via
di.xml - Collects cache tags from view models implementing
IdentityInterface - Properly handles Varnish ESI blocks to prevent incorrect cache purging
- Validates that requested classes implement
ArgumentInterface
Cache handling for ESI blocks:
2. Layout Debugging (Developer Mode Only)
Automatic layout debugging tools enabled when Magento is in developer mode.
Features:
- Visual block hierarchy display
- Layout XML structure viewer
- Block rendering time tracking
- Cache status indicators
Automatically enabled when:
Configuration:
The debugging information is controlled by Hryvinskyi\Base\Helper\Config:
- Only works in developer mode (
State::MODE_DEVELOPER) - Injected into responses via event observers
- No configuration needed - works out of the box
What you get:
- Block nesting and parent-child relationships
- Template file locations with full paths
- Block class names and cache keys
- Layout handle processing order
- Visual hierarchy with indentation
3. Extensible Admin Menu
A reusable dropdown menu component for Magento admin pages that can be configured entirely via layout XML. Perfect for creating navigation menus in custom admin modules.
Features:
- Fully configurable via layout XML (no PHP code required)
- Route-based URL generation with parameters support
- Sortable menu items with sort_order
- Custom CSS classes and icons per item
- Translatable labels
- Reusable across multiple modules
Basic Usage in Layout XML:
Creating a Reusable Menu Handle:
Create a shared layout handle file (e.g., mymodule_menu.xml) to avoid duplication:
Then include it in your page layouts:
Menu Item Configuration Options:
| Option | Type | Required | Description |
|---|---|---|---|
label |
string | Yes | Menu item text (supports translation with translate="true") |
route |
string | Yes | Magento route path (e.g., module/controller/action) |
route_params |
array | No | Route parameters (e.g., section, id) |
sort_order |
number | No | Order of items (default: 0, lower = first) |
class |
string | No | CSS class(es) for the menu item |
icon |
string | No | SVG or HTML icon content |
is_active |
boolean | No | Show/hide item (default: true) |
Custom Menu Icon:
Menu Item with Icon:
Yii2 Framework Helper Classes
This module provides proven, battle-tested helper classes from the Yii2 framework, adapted for Magento 2.
ArrayHelper
Comprehensive array manipulation utilities with 30+ methods for working with arrays and objects.
Key Methods:
| Method | Description |
|---|---|
getValue($array, $key, $default) |
Retrieve nested values using dot notation (user.address.street) |
setValue(&$array, $key, $value) |
Set nested values using dot notation |
remove(&$array, $key, $default) |
Remove and return array element |
merge($a, $b) |
Recursively merge arrays with smart key handling |
index($array, $key) |
Index/group arrays by specified keys |
getColumn($array, $name) |
Extract column values from multidimensional arrays |
map($array, $from, $to, $group) |
Build key-value maps from arrays |
filter($array, $filters) |
Filter array using dot notation rules |
multisort(&$array, $key, $direction) |
Sort by multiple keys with different directions |
toArray($object, $properties, $recursive) |
Convert objects to arrays with property mapping |
isAssociative($array, $allStrings) |
Check if array is associative |
isIndexed($array, $consecutive) |
Check if array is indexed |
htmlEncode($data, $valuesOnly, $charset) |
Encode HTML entities recursively |
htmlDecode($data, $valuesOnly) |
Decode HTML entities recursively |
keyExists($key, $array, $caseSensitive) |
Check key existence with case options |
isIn($needle, $haystack, $strict) |
Check value membership |
isSubset($needles, $haystack, $strict) |
Check if all values exist |
Advanced Features:
- UnsetArrayValue: Mark array values for removal during merge
- ReplaceArrayValue: Force replacement instead of recursive merge
Usage Examples:
Html
HTML generation helper with 40+ methods for programmatic HTML creation and manipulation.
Element Generation:
tag($name, $content, $options)- Generate any HTML taga($text, $url, $options)- Hyperlinksmailto($text, $email, $options)- Email linksimg($src, $options)- Imageslabel($content, $for, $options)- Labelsbutton($content, $options)- ButtonssubmitButton($content, $options)- Submit buttonsresetButton($content, $options)- Reset buttons
Form Generation:
beginForm($action, $method, $formKey, $options)- Form opening with CSRFendForm()- Form closinginput($type, $name, $value, $options)- Generic inputtextInput($name, $value, $options)- Text inputhiddenInput($name, $value, $options)- Hidden inputpasswordInput($name, $value, $options)- Password inputfileInput($name, $value, $options)- File inputtextarea($name, $value, $options)- Textarearadio($name, $checked, $options)- Radio buttoncheckbox($name, $checked, $options)- Checkbox
Lists and Selections:
dropDownList($name, $selection, $items, $options)- Dropdown selectlistBox($name, $selection, $items, $options)- Multi-select listcheckboxList($name, $selection, $items, $options)- Checkbox listradioList($name, $selection, $items, $options)- Radio button listul($items, $options)- Unordered listol($items, $options)- Ordered list
Asset Tags:
cssFile($url, $options)- CSS link tag with IE conditional supportjsFile($url, $options)- JavaScript script tag with IE conditional support
CSS/Style Manipulation:
addCssClass(&$options, $class)- Add CSS class(es)removeCssClass(&$options, $class)- Remove CSS class(es)addCssStyle(&$options, $style, $overwrite)- Add inline stylesremoveCssStyle(&$options, $properties)- Remove inline styles
Utilities:
encode($content, $doubleEncode)- HTML entity encodingdecode($content)- HTML entity decodingrenderTagAttributes($attributes)- Render attribute string with data-* support
Usage Examples:
Json
JSON encoding/decoding utilities with enhanced error handling and features beyond native PHP JSON functions.
Features:
- Enhanced error handling with descriptive messages
- Pretty print support via static property
- Object type preservation control
- HTML-safe encoding for embedding in attributes
- Circular reference detection
Methods:
encode($value, $options)- Encode with error handlinghtmlEncode($value)- HTML-safe encoding (escapes quotes, tags, amp, apos)decode($json, $asArray)- Decode with error handling
Properties:
$prettyPrint- Enable/disable pretty printing (null = use encode options)$keepObjectType- Avoid objects with zero-indexed keys being encoded as arrays
Usage Examples:
VarDumper
Advanced variable dumping for debugging with syntax highlighting and circular reference handling.
Features:
- Enhanced var_dump with better formatting
- Handles circular references safely
- Configurable depth limits
- Syntax highlighting support
- Export variables as valid PHP code
- Support for complex objects and closures
Methods:
dump($var, $depth, $highlight)- Display variable contentsdumpAsString($var, $depth, $highlight)- Get dump as stringexport($var)- Export as executable PHP codeexportClosure($closure)- Export closure source code
Usage Examples:
Console Utilities (ConsoleHelper)
Comprehensive ANSI terminal control for CLI commands with 30+ methods for creating rich console applications.
Categories:
- Cursor Control: Move, position, show/hide cursor
- Screen Control: Clear screen, scroll, save/restore positions
- Colors & Formatting: Foreground/background colors, text styles
- Input/Output: Styled output, user input, prompts
- Progress Bars: Visual progress indicators with ETA
- Utilities: Screen size detection, text wrapping, platform detection
Cursor Control
Screen Control
Colors & Formatting
Color Constants:
Usage:
Input/Output
Progress Bars
Utilities
Complete CLI Example
Requirements
- PHP >= 8.0
- Magento 2.x (2.4+ recommended)
License
This module contains code from two sources with dual licensing:
Yii2 Framework Helpers (BSD-3-Clause License)
The helper classes (ArrayHelper, Html, Json, VarDumper, ConsoleHelper) are derived from the Yii2 Framework and are licensed under the BSD-3-Clause License.
- Copyright: © 2008 Yii Software LLC
- License: BSD-3-Clause
- License File: See LICENSE-YII for the full license text
- Original Source: https://github.com/yiisoft/yii2
Magento 2 Modifications (MIT License)
Modifications, adaptations for Magento 2 compatibility, and original features (ViewModelRegistry, ViewModelCacheTags, layout debugging, etc.) are licensed under the MIT License.
- Copyright: © 2019-2024 Volodymyr Hryvinskyi
- License: MIT
- License File: See LICENSE for the full license text
Usage Rights
You are free to use, modify, and distribute this module under the terms of both licenses. The BSD-3-Clause license applies to the Yii2-derived code, and the MIT license applies to the Magento 2 adaptations and original features.