selfphp-framework/selfphp-framework

SelfPhp Framework is a PHP framework for web development. It provides a structure, a set of tools and a way of thinking to help you build a website using PHP.

1.0.9 2024-03-03 05:33 UTC

This package is auto-updated.

Last update: 2024-04-18 09:06:17 UTC


README

Overview

The SP class is a central controller within the SelfPHP Framework, responsible for managing resources, asset handling, and serving as the foundation for controllers and models. This README provides an overview of the class, its methods, and usage.

Table of Contents

Installation

To use the SP class, include the class file in your project or use Composer to install the package.:

Include the class file

require_once 'path/to/SP.php';
use SelfPhp\SP;

Composer installation

composer require selfphp-framework/selfphp-framework

Usage

$sp = new SP();
$sp->setup_config();

// Example: Get application name
$appName = $sp->app_name();

// Example: Serve JSON response
$data = ['key' => 'value'];
$jsonResponse = $sp->serve_json($data);

Configuration

Ensure that the config directory contains the necessary configuration files. The SP class automatically loads these configurations during initialization.

Methods

Constructor

public function __construct()

Initializes the SP class, loading application configurations.

request_config

public function request_config($config)

Requests and returns a specified configuration file.

serve_json

public function serve_json(array $data)

Returns a JSON-encoded representation of an array.

setup_config

public function setup_config()

Set up configurations.

env

public function env($var_name)

Retrieves the value of an environment variable.

app_name

public function app_name()

Gets the application name.

domain

public function domain()

Retrieves the application domain.

login_page

public function login_page()

Retrieves the login page name.

dashboard_page

public function dashboard_page()

Retrieves the dashboard page name.

verify_domain_format

public function verify_domain_format($domain=null)

Verifies the format of the provided domain.

public_path

public function public_path($path=null)

Constructs the public path by appending the path to the application domain.

asset_path

public function asset_path($path=null)

Constructs the asset path by appending the path to the application domain.

storage_path

public function storage_path($path=null)

Constructs the storage path by appending the path to the application domain.

resource

public function resource($view, $data=[])

Requires and parses a view file, providing the data to be used.

scanDirectory

public function scanDirectory($resourcePath)

Scans a directory and returns an array of file paths.

fileParser

public function fileParser($data=[], $filename = null)

Parses HTML/PHP files with post data.

csvToArray

public static function csvToArray($filepath, $maxLength = 1000)

Converts CSV file data to an associative array.

storageAdd

public static function storageAdd($fileMetadata, $path)

Moves and stores a file in the application's storage directory.

initSqlDebug

public static function initSqlDebug($dbConnection = null)

Initializes SQL debugging based on the DEBUG environment variable.

debugBacktraceShow

public static function debugBacktraceShow($exception = null)

Shows debug backtrace based on the DEBUG environment variable.