PHPackages                             paheon/meowbase - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. paheon/meowbase

ActiveFramework[Debugging &amp; Profiling](/categories/debugging)

paheon/meowbase
===============

Meow Base - Lightweight PHP framework for Web environment and CLI

v1.3.3(4mo ago)029MITPHPPHP ^8.2

Since Dec 11Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/paheon/MeowBase)[ Packagist](https://packagist.org/packages/paheon/meowbase)[ RSS](/packages/paheon-meowbase/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (10)Versions (10)Used By (0)

MeowBase - lightweight PHP framework for Web and CLI
====================================================

[](#meowbase---lightweight-php-framework-for-web-and-cli)

[![Latest Version](https://camo.githubusercontent.com/2ca6ce8d56d6083488a3c90cb42345c9fa40aa9593cebec5576f54c600c3c3b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706168656f6e2f6d656f77626173652e737667)](https://packagist.org/packages/paheon/meowbase)[![MIT Licensed](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/d098775aad9eafe5d92a6bbc68ec8e3337e87a23d1846dda599fa306f203584b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706168656f6e2f6d656f77626173652e737667)](https://packagist.org/packages/paheon/meowbase)

Overview
--------

[](#overview)

MeowBase is a lightweight PHP framework that provides various functionalities including configuration management, caching, database operations, and performance profiling. It is designed to be simple yet powerful, supporting both CLI and Web environments. MeowBase is the foundational base of the Meow Framework, which is a web-based framework for PHP.

MeowBase introduces two types of classes: Core Classes and Tool Classes. Core Classes are foundation classes for the whole application, creating a single instance for the entire application (though they may create multiple instances in some cases). Tool Classes are used to extend the functionality of the MeowBase framework and can create multiple instances as needed. All tool classes are stored in the Tools sub-directory (Tools namespace).

Core Classes
------------

[](#core-classes)

Among the Core Classes, `Config` and `Profiler` are mandatory and will be loaded automatically when MeowBase is initialized. Other core classes like `SysLog`, `Cache`, and `CachedDB` are optional and can be loaded on demand. This design allows for better resource management and performance optimization. When these optional classes are needed, they can be initialized either through preloading during MeowBase initialization or lazily when first accessed.

The preload behavior can be controlled by setting the `$preload` parameter to true in the MeowBase constructor. When preloaded, these classes will be initialized immediately and stored in MeowBase's data members. If not preloaded, they will be initialized only when first accessed through the lazy loading mechanism, which calls `initLogger()`, `initCache()`, or `initCacheDB()` as needed.

This flexible loading approach helps optimize resource usage - if your application doesn't need logging, caching, or database functionality, these components won't be loaded, resulting in faster execution and lower memory usage.

The MeowBase configuration is an array variable that is returned from an anonymous function, `$getSysConfig`, and stored in a PHP file, `etc/config.php`. Developers may override the default configuration using `$localSettings`. The profiler records the time used for each process to help developers find performance bottlenecks. It also provides a 'group' option to record the process time for a group of processes. These two features, configuration and profiler, are natively supported by MeowBase and can be used by any Meow Framework components. Other features are optional and can be loaded on demand.

The logging system, `SysLog` class, uses the Katzgrau/KLogger package to provide logging services. It supports multiple log levels and file rotation. For details, please refer to the [KLogger documentation](https://github.com/katzgrau/KLogger).

The cache system, `Cache` class, is based on the Symfony Cache component and simplifies the cache key building process. It also supports multiple cache adapters and keeps data in memory for faster access. However, only the file adapter and memcached adapter are currently supported. More adapters may be added in the future. For details, please refer to the [Symfony Cache documentation](https://symfony.com/doc/current/components/cache.html).

The database system, `CachedDB` class, inherits from Medoo and adds caching and logging capabilities on top of it. All cached functions have the prefix 'cached', such as `cachedSelect()`, `cachedGet()`, `cachedCalc()` and `cachedHas()`, to distinguish them from the original non-cached functions. All original functions from Medoo, like `select()` and `get()`, do not have caching capabilities but they may use the logging function to log query statements and query results. For more details about Medoo, please refer to the [Medoo documentation](https://medoo.in/api/new).

Tools Classes
-------------

[](#tools-classes)

Unlike Core Classes, Tools Classes are designed to be instantiated on demand and can create multiple instances as needed. These classes are stored in the Tools sub-directory and can be instantiated anywhere in your application. Each instantiation creates a new instance, allowing for different configurations and states to be maintained simultaneously.

The `DTree` class is a versatile and efficient tree data structure implementation in PHP. It is designed to handle hierarchical data with ease, providing a robust set of features for managing tree nodes. The class supports operations such as adding, replacing, deleting, and sorting nodes, making it suitable for a wide range of applications, from simple data organization to complex hierarchical data management.

The `Mailer` class provides email functionality through PHPMailer integration, supporting both direct mode and asynchronous mode email sending, with features for handling attachments, embedded images, and HTML content. For PHPMailer details, please refer to [PHPMailer](https://github.com/PHPMailer/PHPMailer).

The `File` class offers file system operations with path management and temporary file handling capabilities. Many functions are static methods including `getFilePath()`, `getFileName()`, and `getFileExt()` for convenient file path parsing.

The `Url` class provides URL manipulation and validation features, including URL building, modification, and information retrieval.

The `Mime` class handles MIME type detection and conversion, supporting file-to-MIME type mapping and icon association. It integrates with the Shared MIME-Info database for accurate MIME type detection.

The `PHP` class provides utility functions for PHP environment checks. All member functions are static functions that may be called directly.

The `CsvDB` class provides an efficient solution for managing CSV files as a database system for small datasets. For large datasets, please consider using a more robust database system.

The `Autoload` class provides dynamic autoload management capabilities, allowing you to add PSR-4, PSR-0, and classmap entries at runtime without modifying composer.json. This is particularly useful for plugin systems and dynamic module loading.

The `JsonAPI` class provides a robust solution for handling JSON API requests and responses. It supports various HTTP methods (GET, POST, PUT, DELETE, etc.), API key authentication, custom headers, SSL configuration, and automatic retry mechanisms. The class can be used both as an API client (for making requests to external APIs) and as an API server (for handling incoming API requests and sending responses).

Getting Started
---------------

[](#getting-started)

To use MeowBase, first initialize the `Config` object with a user-defined configuration file in the etc folder. Then pass the `Config` object to the `MeowBase` constructor to generate the `MeowBase` object. `MeowBase` will load the configuration and initialize the other components automatically. Developers can use the `MeowBase` object to access all core components, such as `config`, `log`, `cache`, `db` and `profiler`.

Users may copy or rename `config-example.php` to `config.php` and modify the configuration in it.

Here is a simple example to show how to use MeowBase:

```
