second commit
This commit is contained in:
commit
27261b1e50
|
|
@ -0,0 +1,4 @@
|
|||
/vendor/
|
||||
/logs/
|
||||
/storage/
|
||||
.env
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Project Documentation
|
||||
|
||||
This file will contain project documentation.
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Core\Controller;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
class AboutController extends Controller
|
||||
{
|
||||
public function index(): void
|
||||
{
|
||||
|
||||
|
||||
$this->render('pages/about', [
|
||||
'title' => 'About Us - Wizdom Networks',
|
||||
'content' => '<h1>About Wizdom Networks</h1>
|
||||
<p>We specialize in delivering top-notch IT solutions to help your business thrive.</p>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
class ClientsController
|
||||
{
|
||||
// Placeholder for future implementation
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Core\Controller;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
|
||||
/**
|
||||
* Contact Controller
|
||||
*
|
||||
* This controller handles the logic for rendering the contact page of the application.
|
||||
*/
|
||||
class ContactController extends Controller
|
||||
{
|
||||
/**
|
||||
* Index method for the ContactController.
|
||||
*
|
||||
* This method prepares the data for the contact page and renders the corresponding view.
|
||||
*
|
||||
* @throws \Exception If the view cannot be rendered or an error occurs.
|
||||
*/
|
||||
public function index(): void
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Entering ContactController::index");
|
||||
|
||||
// Prepare data for the contact page
|
||||
$data = [
|
||||
'title' => 'Contact Us - Wizdom Networks',
|
||||
'description' => 'Get in touch with our team for inquiries and support.',
|
||||
];
|
||||
|
||||
// Render the contact page view
|
||||
$this->render('pages/contact', $data);
|
||||
|
||||
Logger::info("[DEBUG] Successfully rendered contact page");
|
||||
} catch (\Exception $e) {
|
||||
// Log and handle any exceptions
|
||||
ErrorHandler::exception($e);
|
||||
throw $e; // Rethrow or handle as needed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
class EmergencySupportController
|
||||
{
|
||||
// Placeholder for future implementation
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
class HelpDeskController {
|
||||
// Placeholder
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Core\Controller;
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Displays the home page.
|
||||
*/
|
||||
public function index(): void
|
||||
{
|
||||
Logger::info("HomeController::index() invoked.");
|
||||
|
||||
$data = [
|
||||
'title' => 'Welcome to Wizdom Networks',
|
||||
'description' => 'Your trusted IT consulting partner.',
|
||||
];
|
||||
|
||||
try {
|
||||
$this->render('pages/home', $data);
|
||||
Logger::info("Home page rendered successfully.");
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("Failed to render home page: " . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo "An internal error occurred.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Core\Controller;
|
||||
|
||||
class ServicesController extends Controller
|
||||
{
|
||||
public function index(): void
|
||||
{
|
||||
// Render the services page with the layout
|
||||
$this->render('pages/services', ['title' => 'Our Services']);
|
||||
}
|
||||
|
||||
public function itConsulting(): void
|
||||
{
|
||||
|
||||
|
||||
$this->render('pages/services/it_consulting', [
|
||||
'title' => 'IT Consulting - Wizdom Networks',
|
||||
'content' => '<h1>IT Consulting</h1>
|
||||
<p>We provide tailored IT solutions to help your business thrive.</p>'
|
||||
]);
|
||||
}
|
||||
|
||||
public function emergencySupport(): void
|
||||
{
|
||||
|
||||
|
||||
$this->render('pages/services/emergency_support', [
|
||||
'title' => 'Emergency Support - Wizdom Networks',
|
||||
'content' => '<h1>Emergency Support</h1>
|
||||
<p>24/7 emergency IT support to ensure smooth operations.</p>'
|
||||
]);
|
||||
}
|
||||
|
||||
public function managedServices(): void
|
||||
{
|
||||
|
||||
|
||||
// Render the managed services page with the layout
|
||||
$this->render('pages/services/managed_services', [
|
||||
'title' => 'Managed Services',
|
||||
'content' => '<h1>Managed Services</h1>
|
||||
<p>We offer a wide array of managed services</p>'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Controllers;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Core\Controller;
|
||||
|
||||
class TestimonialsController extends Controller
|
||||
{
|
||||
public function index(): void
|
||||
{
|
||||
$contactForm = $this->getContactForm('Want to leave us feedback?');
|
||||
|
||||
$this->render('pages/testimonials', [
|
||||
'title' => 'Testimonials - Wizdom Networks',
|
||||
'content' => '<h1>Testimonials</h1>
|
||||
<p>Here\'s what our clients have to say about us:</p>' . $contactForm
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Core;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
/**
|
||||
* Render a view file with the given data.
|
||||
*
|
||||
* @param string $view The path to the view file.
|
||||
* @param array $data Data to be extracted and used in the view.
|
||||
* @throws \Exception If the view file cannot be found.
|
||||
*/
|
||||
protected function render(string $view, array $data = []): void
|
||||
{
|
||||
try {
|
||||
// Extract data for use in the view
|
||||
extract($data);
|
||||
|
||||
// Resolve the view path
|
||||
$viewPath = __DIR__ . "/../../resources/views/$view.php";
|
||||
Logger::info("[DEBUG] Resolving view: $view | Path: $viewPath");
|
||||
|
||||
if (file_exists($viewPath)) {
|
||||
Logger::info("[DEBUG] Including view file: $viewPath");
|
||||
include $viewPath;
|
||||
Logger::info("[DEBUG] Successfully rendered view: $view");
|
||||
} else {
|
||||
throw new \Exception("View file not found: $view\nPath: $viewPath");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception with Logger
|
||||
Logger::error("[ERROR] Exception while rendering view: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rendered content of the contact form.
|
||||
*
|
||||
* This method renders the contact form view and returns the output as a string.
|
||||
* It is used for embedding the contact form in various parts of the application.
|
||||
*
|
||||
* @param array $data Optional data to pass to the contact form view.
|
||||
* @return string The rendered contact form HTML.
|
||||
* @throws \Exception If the contact form view cannot be rendered.
|
||||
*/
|
||||
protected function getContactForm(array $data = []): string
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Rendering contact form with data: " . json_encode($data));
|
||||
|
||||
// Buffer output to capture rendered content
|
||||
ob_start();
|
||||
$this->render('partials/contact_form', $data);
|
||||
|
||||
$output = ob_get_clean();
|
||||
|
||||
Logger::info("[DEBUG] Successfully rendered contact form");
|
||||
|
||||
return $output;
|
||||
} catch (\Exception $e) {
|
||||
// Log any exception that occurs
|
||||
Logger::error("[ERROR] Exception while rendering contact form: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Core;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
class Router
|
||||
{
|
||||
protected array $routes = [];
|
||||
|
||||
public function add(string $path, string $controller, string $method): void
|
||||
{
|
||||
// Normalize the path to remove leading/trailing slashes
|
||||
$normalizedPath = trim($path, '/');
|
||||
$this->routes[$normalizedPath] = ['controller' => $controller, 'method' => $method];
|
||||
Logger::info("Route added: $normalizedPath -> $controller::$method");
|
||||
}
|
||||
|
||||
public function dispatch(string $path): void
|
||||
{
|
||||
// Normalize the incoming path to remove leading/trailing slashes
|
||||
$path = trim($path, '/');
|
||||
|
||||
Logger::info("Dispatching path: $path");
|
||||
|
||||
if (!isset($this->routes[$path])) {
|
||||
Logger::error("Route not found: $path");
|
||||
http_response_code(404);
|
||||
echo "404 - Page not found";
|
||||
return;
|
||||
}
|
||||
|
||||
$controllerName = $this->routes[$path]['controller'];
|
||||
$method = $this->routes[$path]['method'];
|
||||
|
||||
Logger::info("Loading controller: $controllerName::$method");
|
||||
|
||||
if (!class_exists($controllerName) || !method_exists($controllerName, $method)) {
|
||||
Logger::error("Controller or method not found: $controllerName::$method");
|
||||
http_response_code(500);
|
||||
echo "500 - Internal server error";
|
||||
return;
|
||||
}
|
||||
|
||||
$controller = new $controllerName();
|
||||
$controller->$method();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Core;
|
||||
|
||||
class View {
|
||||
// Placeholder
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Interfaces;
|
||||
|
||||
class LoggableInterface
|
||||
{
|
||||
// Placeholder for future implementation
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Interfaces;
|
||||
|
||||
class ServiceInterface
|
||||
{
|
||||
// Placeholder for future implementation
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Models;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Client Model
|
||||
*
|
||||
* Handles database operations related to clients.
|
||||
*/
|
||||
class ClientModel
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a client by ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|null
|
||||
*/
|
||||
public function getClientById(int $id): ?array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching client with ID: $id");
|
||||
|
||||
$stmt = $this->db->prepare("SELECT * FROM clients WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
$client = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
Logger::info("[DEBUG] Client data retrieved: " . json_encode($client));
|
||||
|
||||
return $client ?: null;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch client with ID $id: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new client to the database.
|
||||
*
|
||||
* @param array $clientData
|
||||
* @return bool
|
||||
*/
|
||||
public function addClient(array $clientData): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Adding new client: " . json_encode($clientData));
|
||||
|
||||
$stmt = $this->db->prepare(
|
||||
"INSERT INTO clients (name, email, phone) VALUES (:name, :email, :phone)"
|
||||
);
|
||||
$stmt->bindParam(':name', $clientData['name']);
|
||||
$stmt->bindParam(':email', $clientData['email']);
|
||||
$stmt->bindParam(':phone', $clientData['phone']);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
Logger::info("[DEBUG] Client successfully added.");
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to add client: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a client by ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteClientById(int $id): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Deleting client with ID: $id");
|
||||
|
||||
$stmt = $this->db->prepare("DELETE FROM clients WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
Logger::info("[DEBUG] Client with ID $id successfully deleted.");
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to delete client with ID $id: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Models;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Contact Model
|
||||
*
|
||||
* Handles database operations related to contacts.
|
||||
*/
|
||||
class ContactModel
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a contact by ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|null
|
||||
*/
|
||||
public function getContactById(int $id): ?array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching contact with ID: $id");
|
||||
|
||||
$stmt = $this->db->prepare("SELECT * FROM contacts WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
$contact = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
Logger::info("[DEBUG] Contact data retrieved: " . json_encode($contact));
|
||||
|
||||
return $contact ?: null;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch contact with ID $id: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new contact to the database.
|
||||
*
|
||||
* @param array $contactData
|
||||
* @return bool
|
||||
*/
|
||||
public function addContact(array $contactData): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Adding new contact: " . json_encode($contactData));
|
||||
|
||||
$stmt = $this->db->prepare(
|
||||
"INSERT INTO contacts (name, email, message) VALUES (:name, :email, :message)"
|
||||
);
|
||||
$stmt->bindParam(':name', $contactData['name']);
|
||||
$stmt->bindParam(':email', $contactData['email']);
|
||||
$stmt->bindParam(':message', $contactData['message']);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
Logger::info("[DEBUG] Contact successfully added.");
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to add contact: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a contact by ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteContactById(int $id): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Deleting contact with ID: $id");
|
||||
|
||||
$stmt = $this->db->prepare("DELETE FROM contacts WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
Logger::info("[DEBUG] Contact with ID $id successfully deleted.");
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to delete contact with ID $id: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Models;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Service Model
|
||||
*
|
||||
* Handles database operations related to services.
|
||||
*/
|
||||
class ServiceModel
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all services.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllServices(): array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching all services");
|
||||
|
||||
$stmt = $this->db->query("SELECT * FROM services");
|
||||
$services = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
Logger::info("[DEBUG] Retrieved services: " . json_encode($services));
|
||||
|
||||
return $services;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch services: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a service by ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|null
|
||||
*/
|
||||
public function getServiceById(int $id): ?array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching service with ID: $id");
|
||||
|
||||
$stmt = $this->db->prepare("SELECT * FROM services WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
$service = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
Logger::info("[DEBUG] Service data retrieved: " . json_encode($service));
|
||||
|
||||
return $service ?: null;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch service with ID $id: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new service to the database.
|
||||
*
|
||||
* @param array $serviceData
|
||||
* @return bool
|
||||
*/
|
||||
public function addService(array $serviceData): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Adding new service: " . json_encode($serviceData));
|
||||
|
||||
$stmt = $this->db->prepare(
|
||||
"INSERT INTO services (name, description, price) VALUES (:name, :description, :price)"
|
||||
);
|
||||
$stmt->bindParam(':name', $serviceData['name']);
|
||||
$stmt->bindParam(':description', $serviceData['description']);
|
||||
$stmt->bindParam(':price', $serviceData['price']);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
Logger::info("[DEBUG] Service successfully added.");
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to add service: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Models;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Service Model
|
||||
*
|
||||
* Handles database operations related to services.
|
||||
*/
|
||||
class ServiceModel
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all services.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllServices(): array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching all services");
|
||||
|
||||
$stmt = $this->db->query("SELECT * FROM services");
|
||||
$services = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
Logger::info("[DEBUG] Retrieved services: " . json_encode($services));
|
||||
|
||||
return $services;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch services: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a service by ID.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|null
|
||||
*/
|
||||
public function getServiceById(int $id): ?array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching service with ID: $id");
|
||||
|
||||
$stmt = $this->db->prepare("SELECT * FROM services WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
$service = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
Logger::info("[DEBUG] Service data retrieved: " . json_encode($service));
|
||||
|
||||
return $service ?: null;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch service with ID $id: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new service to the database.
|
||||
*
|
||||
* @param array $serviceData
|
||||
* @return bool
|
||||
*/
|
||||
public function addService(array $serviceData): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Adding new service: " . json_encode($serviceData));
|
||||
|
||||
$stmt = $this->db->prepare(
|
||||
"INSERT INTO services (name, description, price) VALUES (:name, :description, :price)"
|
||||
);
|
||||
$stmt->bindParam(':name', $serviceData['name']);
|
||||
$stmt->bindParam(':description', $serviceData['description']);
|
||||
$stmt->bindParam(':price', $serviceData['price']);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
Logger::info("[DEBUG] Service successfully added.");
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to add service: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Services;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Emergency Support Service
|
||||
*
|
||||
* Handles business logic related to emergency IT support services.
|
||||
*/
|
||||
class EmergencySupportService
|
||||
{
|
||||
/**
|
||||
* Provide emergency support service details.
|
||||
*
|
||||
* @return array Details of the emergency support service.
|
||||
*/
|
||||
public function getServiceDetails(): array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching emergency support service details");
|
||||
|
||||
$details = [
|
||||
'name' => 'Emergency Support',
|
||||
'description' => 'Round-the-clock emergency IT support for critical issues.',
|
||||
'features' => [
|
||||
'24/7 availability',
|
||||
'Rapid response',
|
||||
'Critical system recovery',
|
||||
],
|
||||
'price' => 'Custom pricing based on severity and scope',
|
||||
];
|
||||
|
||||
Logger::info("[DEBUG] Retrieved emergency support service details: " . json_encode($details));
|
||||
|
||||
return $details;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch emergency support service details: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Services;
|
||||
|
||||
class HelpDeskService
|
||||
{
|
||||
// Placeholder for future implementation
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Services;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* IT Consulting Service
|
||||
*
|
||||
* Handles business logic related to IT consulting services.
|
||||
*/
|
||||
class ITConsultingService
|
||||
{
|
||||
/**
|
||||
* Provide IT consulting service details.
|
||||
*
|
||||
* @return array Details of the IT consulting service.
|
||||
*/
|
||||
public function getServiceDetails(): array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching IT consulting service details");
|
||||
|
||||
$details = [
|
||||
'name' => 'IT Consulting',
|
||||
'description' => 'Expert IT consulting services to drive your business forward.',
|
||||
'features' => [
|
||||
'Infrastructure planning',
|
||||
'Cloud integration',
|
||||
'Technology strategy',
|
||||
],
|
||||
'price' => 'Custom pricing based on requirements',
|
||||
];
|
||||
|
||||
Logger::info("[DEBUG] Retrieved IT consulting service details: " . json_encode($details));
|
||||
|
||||
return $details;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch IT consulting service details: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Services;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Managed Hosting Service
|
||||
*
|
||||
* Handles business logic related to managed hosting services.
|
||||
*/
|
||||
class ManagedHostingService
|
||||
{
|
||||
/**
|
||||
* Provide managed hosting service details.
|
||||
*
|
||||
* @return array Details of the managed hosting service.
|
||||
*/
|
||||
public function getServiceDetails(): array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching managed hosting service details");
|
||||
|
||||
$details = [
|
||||
'name' => 'Managed Hosting',
|
||||
'description' => 'Comprehensive managed hosting services to keep your business online.',
|
||||
'features' => [
|
||||
'Server management',
|
||||
'Performance optimization',
|
||||
'Data backups and recovery',
|
||||
],
|
||||
'price' => 'Custom pricing based on hosting requirements',
|
||||
];
|
||||
|
||||
Logger::info("[DEBUG] Retrieved managed hosting service details: " . json_encode($details));
|
||||
|
||||
return $details;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch managed hosting service details: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Services;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Online Brand Management Service
|
||||
*
|
||||
* Handles business logic related to online brand management services.
|
||||
*/
|
||||
class OnlineBrandManagementService
|
||||
{
|
||||
/**
|
||||
* Provide online brand management service details.
|
||||
*
|
||||
* @return array Details of the online brand management service.
|
||||
*/
|
||||
public function getServiceDetails(): array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching online brand management service details");
|
||||
|
||||
$details = [
|
||||
'name' => 'Online Brand Management',
|
||||
'description' => 'Strategic online brand management to enhance your digital presence.',
|
||||
'features' => [
|
||||
'Social media management',
|
||||
'Reputation monitoring',
|
||||
'Content strategy',
|
||||
],
|
||||
'price' => 'Custom pricing based on campaign requirements',
|
||||
];
|
||||
|
||||
Logger::info("[DEBUG] Retrieved online brand management service details: " . json_encode($details));
|
||||
|
||||
return $details;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch online brand management service details: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Services;
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
|
||||
/**
|
||||
* Project Management Service
|
||||
*
|
||||
* Handles business logic related to project management services.
|
||||
*/
|
||||
class ProjectManagementService
|
||||
{
|
||||
/**
|
||||
* Provide project management service details.
|
||||
*
|
||||
* @return array Details of the project management service.
|
||||
*/
|
||||
public function getServiceDetails(): array
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Fetching project management service details");
|
||||
|
||||
$details = [
|
||||
'name' => 'Project Management',
|
||||
'description' => 'Professional project management to ensure success from start to finish.',
|
||||
'features' => [
|
||||
'Planning and scheduling',
|
||||
'Resource allocation',
|
||||
'Risk management',
|
||||
],
|
||||
'price' => 'Custom pricing based on project scope',
|
||||
];
|
||||
|
||||
Logger::info("[DEBUG] Retrieved project management service details: " . json_encode($details));
|
||||
|
||||
return $details;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error("[ERROR] Failed to fetch project management service details: " . $e->getMessage());
|
||||
ErrorHandler::exception($e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
/**
|
||||
* Utility class to inspect declared classes and autoloading in the application.
|
||||
*/
|
||||
class ClassInspector
|
||||
{
|
||||
/**
|
||||
* Get all declared classes within a given namespace.
|
||||
*
|
||||
* @param string $namespace The namespace to filter by.
|
||||
* @return array An array of fully qualified class names in the namespace.
|
||||
*/
|
||||
public static function getClassesInNamespace(string $namespace): array
|
||||
{
|
||||
$classes = get_declared_classes();
|
||||
$namespaceClasses = [];
|
||||
|
||||
foreach ($classes as $class) {
|
||||
if (str_starts_with($class, $namespace . '\\')) {
|
||||
$namespaceClasses[] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
return $namespaceClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the top-level namespace of the current application.
|
||||
* Assumes PSR-4 autoloading and looks at composer.json.
|
||||
*
|
||||
* @return string|null The detected namespace, or null if not found.
|
||||
*/
|
||||
public static function getTopLevelNamespace(): ?string
|
||||
{
|
||||
$composerFile = __DIR__ . '/../../composer.json'; // Adjust path as needed
|
||||
|
||||
if (!file_exists($composerFile)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$composerData = json_decode(file_get_contents($composerFile), true);
|
||||
if (!isset($composerData['autoload']['psr-4'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$namespaces = array_keys($composerData['autoload']['psr-4']);
|
||||
return rtrim($namespaces[0], '\\'); // Return the first namespace as the top-level
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare declared classes with all possible classes in the namespace directory.
|
||||
*
|
||||
* @param string $namespace The namespace to inspect.
|
||||
* @param string $baseDir The base directory for the namespace.
|
||||
* @return array An array with loaded and not-loaded class information.
|
||||
*/
|
||||
public static function compareLoadedClasses(string $namespace, string $baseDir): array
|
||||
{
|
||||
$loadedClasses = self::getClassesInNamespace($namespace);
|
||||
|
||||
// Get all possible classes from the directory
|
||||
$allClasses = [];
|
||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($baseDir));
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->getExtension() === 'php') {
|
||||
$relativePath = str_replace([$baseDir, '/', '.php'], ['', '\\', ''], $file->getPathname());
|
||||
$className = $namespace . '\\' . $relativePath;
|
||||
$className = str_replace('\\\\', '\\', $className); // Remove double backslashes
|
||||
$allClasses[$className] = $file->getPathname();
|
||||
}
|
||||
}
|
||||
|
||||
// Separate loaded and not loaded
|
||||
$classDetails = [];
|
||||
foreach ($allClasses as $className => $path) {
|
||||
$status = class_exists($className, true) ? 'Loaded' : 'Not Loaded';
|
||||
$classDetails[] = [
|
||||
'class' => self::getClassNameOnly($className),
|
||||
'path' => $path,
|
||||
'status' => $status,
|
||||
];
|
||||
}
|
||||
|
||||
return $classDetails;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the class name from a fully qualified class name.
|
||||
*
|
||||
* @param string $class Fully qualified class name.
|
||||
* @return string The class name without the namespace.
|
||||
*/
|
||||
private static function getClassNameOnly(string $class): string
|
||||
{
|
||||
$parts = explode('\\', $class);
|
||||
return end($parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the results in a table format.
|
||||
*
|
||||
* @param string $namespace The namespace to inspect.
|
||||
* @param string $baseDir The base directory for the namespace.
|
||||
* @param bool $useHtml Whether to generate the table as HTML (default: true).
|
||||
* @return void
|
||||
*/
|
||||
public static function displayClassTable(string $namespace, string $baseDir, bool $useHtml = true): void
|
||||
{
|
||||
$classDetails = self::compareLoadedClasses($namespace, $baseDir);
|
||||
|
||||
if ($useHtml) {
|
||||
// Generate HTML table
|
||||
echo "<table border='1' cellspacing='0' cellpadding='5'>";
|
||||
echo "<thead>";
|
||||
echo "<tr><th>Class</th><th>Path</th><th>Status</th></tr>";
|
||||
echo "</thead>";
|
||||
echo "<tbody>";
|
||||
|
||||
foreach ($classDetails as $detail) {
|
||||
echo "<tr>";
|
||||
echo "<td>{$detail['class']}</td>";
|
||||
echo "<td>{$detail['path']}</td>";
|
||||
echo "<td>{$detail['status']}</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</tbody>";
|
||||
echo "</table>";
|
||||
} else {
|
||||
// Generate plain text table
|
||||
echo str_pad("Class", 30) . str_pad("Path", 50) . "Status\n";
|
||||
echo str_repeat("-", 100) . "\n";
|
||||
|
||||
foreach ($classDetails as $detail) {
|
||||
echo str_pad($detail['class'], 30) .
|
||||
str_pad($detail['path'], 50) .
|
||||
$detail['status'] . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug all classes in the top-level namespace, showing a table of results.
|
||||
*
|
||||
* @param bool $useHtml Whether to generate the table as HTML (default: true).
|
||||
* @return void
|
||||
*/
|
||||
public static function debugTopLevelNamespace(bool $useHtml = true): void
|
||||
{
|
||||
$namespace = self::getTopLevelNamespace();
|
||||
if (!$namespace) {
|
||||
echo "Top-level namespace could not be determined.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Assume PSR-4 base directory is app/ (adjust if needed)
|
||||
$baseDir = realpath(__DIR__ . '/../../app');
|
||||
if (!$baseDir) {
|
||||
echo "Base directory could not be resolved.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
self::displayClassTable($namespace, $baseDir, $useHtml);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
/**
|
||||
* Database Utility
|
||||
*
|
||||
* A utility for managing database connections and queries.
|
||||
*
|
||||
* Integrates logging for connection status and query execution.
|
||||
*/
|
||||
class Database
|
||||
{
|
||||
/**
|
||||
* @var PDO|null The PDO instance for database connection.
|
||||
*/
|
||||
private ?PDO $connection = null;
|
||||
|
||||
/**
|
||||
* Database constructor.
|
||||
*
|
||||
* Initializes the database connection.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes a connection to the database.
|
||||
*/
|
||||
private function connect(): void
|
||||
{
|
||||
$dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8mb4', getenv('DB_HOST'), getenv('DB_NAME'));
|
||||
|
||||
try {
|
||||
$this->connection = new PDO($dsn, getenv('DB_USER'), getenv('DB_PASSWORD'));
|
||||
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
Logger::info('Database connection established successfully.');
|
||||
} catch (PDOException $e) {
|
||||
Logger::error('Database connection failed: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a query and returns the result.
|
||||
*
|
||||
* @param string $query The SQL query to execute.
|
||||
* @param array $params Parameters for prepared statements (optional).
|
||||
* @return array The query result.
|
||||
*/
|
||||
public function query(string $query, array $params = []): array
|
||||
{
|
||||
try {
|
||||
$stmt = $this->connection->prepare($query);
|
||||
$stmt->execute($params);
|
||||
Logger::info('Query executed successfully: ' . $query);
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
Logger::error('Query failed: ' . $query . ' | Error: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the PDO connection instance.
|
||||
*
|
||||
* @return PDO The PDO instance.
|
||||
*/
|
||||
public function getConnection(): PDO
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
/**
|
||||
* Error Handler Utility
|
||||
*
|
||||
* A utility for handling errors and exceptions globally.
|
||||
*
|
||||
* Automatically logs errors and exceptions using the Logger utility and displays generic error messages to users.
|
||||
*/
|
||||
class ErrorHandler
|
||||
{
|
||||
/**
|
||||
* Registers the custom error and exception handlers.
|
||||
*/
|
||||
public static function register(): void
|
||||
{
|
||||
set_error_handler([self::class, 'handleError']);
|
||||
set_exception_handler([self::class, 'handleException']);
|
||||
Logger::info("ErrorHandler registered successfully.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom error handler.
|
||||
*
|
||||
* Logs the error details and displays a generic error message.
|
||||
*
|
||||
* @param int $errno The error level.
|
||||
* @param string $errstr The error message.
|
||||
* @param string $errfile The file where the error occurred.
|
||||
* @param int $errline The line number where the error occurred.
|
||||
*/
|
||||
public static function handleError(int $errno, string $errstr, string $errfile, int $errline): void
|
||||
{
|
||||
$message = "Error [$errno]: $errstr in $errfile on line $errline";
|
||||
Logger::error($message);
|
||||
http_response_code(500);
|
||||
echo "An internal error occurred. Please try again later.";
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom exception handler.
|
||||
*
|
||||
* Logs the exception details and displays a generic error message.
|
||||
*
|
||||
* @param \Throwable $exception The exception object.
|
||||
*/
|
||||
public static function handleException(\Throwable $exception): void
|
||||
{
|
||||
$message = "Exception: " . $exception->getMessage() . " in " . $exception->getFile() . " on line " . $exception->getLine();
|
||||
Logger::error($message);
|
||||
http_response_code(500);
|
||||
echo "An internal error occurred. Please try again later.";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
/**
|
||||
* Logger Utility
|
||||
*
|
||||
* A utility class for logging messages to a file.
|
||||
*
|
||||
* Supports logging messages at different levels (INFO, WARNING, ERROR) with timestamps.
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* @var string The path to the log file.
|
||||
*/
|
||||
protected static string $logFile = __DIR__ . '/../../logs/app.log';
|
||||
|
||||
/**
|
||||
* Logs a message to the log file.
|
||||
*
|
||||
* @param string $level The log level (e.g., INFO, WARNING, ERROR).
|
||||
* @param string $message The log message.
|
||||
*/
|
||||
public static function log(string $level, string $message): void
|
||||
{
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
$formattedMessage = "[$timestamp] [$level]: $message" . PHP_EOL;
|
||||
|
||||
file_put_contents(self::$logFile, $formattedMessage, FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an informational message.
|
||||
*
|
||||
* @param string $message The log message.
|
||||
*/
|
||||
public static function info(string $message): void
|
||||
{
|
||||
self::log('INFO', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a warning message.
|
||||
*
|
||||
* @param string $message The log message.
|
||||
*/
|
||||
public static function warning(string $message): void
|
||||
{
|
||||
self::log('WARNING', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error message.
|
||||
*
|
||||
* @param string $message The log message.
|
||||
*/
|
||||
public static function error(string $message): void
|
||||
{
|
||||
self::log('ERROR', $message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
/**
|
||||
* Mailer Utility
|
||||
*
|
||||
* A utility class for sending emails using PHPMailer.
|
||||
*
|
||||
* Integrates logging for email success and failure events.
|
||||
*/
|
||||
class Mailer
|
||||
{
|
||||
/**
|
||||
* @var PHPMailer The PHPMailer instance used for sending emails.
|
||||
*/
|
||||
protected PHPMailer $mailer;
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* Initializes the PHPMailer instance and configures it based on environment variables.
|
||||
*
|
||||
* @throws Exception If PHPMailer configuration fails.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->mailer = new PHPMailer(true);
|
||||
$this->configure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the PHPMailer instance.
|
||||
*
|
||||
* Reads email configuration from environment variables such as MAIL_HOST, MAIL_USER, MAIL_PASSWORD, etc.
|
||||
*
|
||||
* @throws Exception If any configuration errors occur.
|
||||
*/
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->mailer->isSMTP();
|
||||
$this->mailer->Host = getenv('MAIL_HOST');
|
||||
$this->mailer->SMTPAuth = true;
|
||||
$this->mailer->Username = getenv('MAIL_USER');
|
||||
$this->mailer->Password = getenv('MAIL_PASSWORD');
|
||||
$this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$this->mailer->Port = (int) getenv('MAIL_PORT');
|
||||
$this->mailer->setFrom(getenv('MAIL_FROM_EMAIL'), getenv('MAIL_FROM_NAME'));
|
||||
Logger::info('Mailer configured successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an email.
|
||||
*
|
||||
* @param string $to The recipient's email address.
|
||||
* @param string $subject The email subject.
|
||||
* @param string $body The HTML content of the email.
|
||||
* @param string $altBody The plain-text alternative content of the email (optional).
|
||||
*
|
||||
* @return bool True if the email was sent successfully, false otherwise.
|
||||
*/
|
||||
public function send(string $to, string $subject, string $body, string $altBody = ''): bool
|
||||
{
|
||||
try {
|
||||
$this->mailer->addAddress($to);
|
||||
$this->mailer->Subject = $subject;
|
||||
$this->mailer->Body = $body;
|
||||
$this->mailer->AltBody = $altBody;
|
||||
|
||||
if ($this->mailer->send()) {
|
||||
Logger::info("Email sent successfully to $to with subject: $subject.");
|
||||
return true;
|
||||
} else {
|
||||
Logger::error("Failed to send email to $to with subject: $subject.");
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Logger::error("Mailer error while sending email to $to: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
class NamespaceUpdater
|
||||
{
|
||||
public function updateNamespaces(string $basePath, ?string $autoloadNamespace = null): void
|
||||
{
|
||||
// Ensure path ends with a directory separator
|
||||
$basePath = rtrim($basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
|
||||
// Determine namespace base from composer.json or use default
|
||||
$namespaceBase = $autoloadNamespace ?? $this->getNamespaceFromComposer($basePath) ?? 'App\\';
|
||||
$namespaceBase = rtrim(str_replace('\\', '\\', $namespaceBase), '\\') . '\\';
|
||||
|
||||
$files = $this->findPhpFiles($basePath);
|
||||
foreach ($files as $file) {
|
||||
$this->updateNamespace($file, $namespaceBase, $basePath);
|
||||
}
|
||||
|
||||
echo "Namespace update complete.\n";
|
||||
}
|
||||
|
||||
private function getNamespaceFromComposer(string $basePath): ?string
|
||||
{
|
||||
$composerPath = $basePath . 'composer.json';
|
||||
|
||||
if (!file_exists($composerPath)) {
|
||||
echo "composer.json not found. Using default namespace.\n";
|
||||
return null;
|
||||
}
|
||||
|
||||
$composerConfig = json_decode(file_get_contents($composerPath), true);
|
||||
|
||||
if (
|
||||
isset($composerConfig['autoload']['psr-4']) &&
|
||||
is_array($composerConfig['autoload']['psr-4'])
|
||||
) {
|
||||
$namespaces = array_keys($composerConfig['autoload']['psr-4']);
|
||||
return $namespaces[0] ?? null;
|
||||
}
|
||||
|
||||
echo "No PSR-4 autoload namespace found in composer.json. Using default namespace.\n";
|
||||
return null;
|
||||
}
|
||||
|
||||
private function findPhpFiles(string $directory): array
|
||||
{
|
||||
$phpFiles = [];
|
||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->getExtension() === 'php' && strpos($file->getPathname(), DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) === false) {
|
||||
$phpFiles[] = $file->getPathname();
|
||||
}
|
||||
}
|
||||
|
||||
return $phpFiles;
|
||||
}
|
||||
|
||||
private function updateNamespace(string $filePath, string $namespaceBase, string $basePath): void
|
||||
{
|
||||
// Get the relative path from the base directory
|
||||
$relativePath = str_replace($basePath, '', $filePath);
|
||||
|
||||
// Remove the 'app/' prefix from the relative path
|
||||
if (strpos($relativePath, 'app/') === 0) {
|
||||
$relativePath = substr($relativePath, strlen('app/'));
|
||||
}
|
||||
|
||||
// Build the namespace
|
||||
$namespaceParts = explode(DIRECTORY_SEPARATOR, dirname($relativePath));
|
||||
$namespace = $namespaceBase . implode('\\', $namespaceParts);
|
||||
|
||||
// Get the file content
|
||||
$content = file_get_contents($filePath);
|
||||
|
||||
// Skip files without a namespace declaration
|
||||
if (!preg_match('/^namespace\s+[^;]+;/m', $content)) {
|
||||
echo "Skipping file without namespace: $filePath\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if the namespace is already correct
|
||||
if (preg_match('/^namespace\s+' . preg_quote($namespace, '/') . ';$/m', $content)) {
|
||||
echo "Namespace already correct in file: $filePath\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace or add the namespace
|
||||
$content = preg_replace('/^namespace\s+[^;]+;/m', "namespace $namespace;", $content);
|
||||
|
||||
// Save the updated file
|
||||
file_put_contents($filePath, $content);
|
||||
echo "Updated namespace in file: $filePath\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
/**
|
||||
* Sanitizer Utility
|
||||
*
|
||||
* Provides methods for sanitizing various types of data, including strings, emails, URLs, and arrays.
|
||||
*
|
||||
* Logs sanitized data for debugging and traceability.
|
||||
*/
|
||||
class Sanitizer
|
||||
{
|
||||
/**
|
||||
* Sanitizes a string by removing harmful characters.
|
||||
*
|
||||
* @param string $value The string to sanitize.
|
||||
* @return string The sanitized string.
|
||||
*/
|
||||
public static function sanitizeString(string $value): string
|
||||
{
|
||||
$sanitized = filter_var($value, FILTER_SANITIZE_STRING);
|
||||
Logger::info("Sanitized string: Original: $value | Sanitized: $sanitized");
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes an email address.
|
||||
*
|
||||
* @param string $value The email address to sanitize.
|
||||
* @return string The sanitized email address.
|
||||
*/
|
||||
public static function sanitizeEmail(string $value): string
|
||||
{
|
||||
$sanitized = filter_var($value, FILTER_SANITIZE_EMAIL);
|
||||
Logger::info("Sanitized email: Original: $value | Sanitized: $sanitized");
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes a URL.
|
||||
*
|
||||
* @param string $value The URL to sanitize.
|
||||
* @return string The sanitized URL.
|
||||
*/
|
||||
public static function sanitizeURL(string $value): string
|
||||
{
|
||||
$sanitized = filter_var($value, FILTER_SANITIZE_URL);
|
||||
Logger::info("Sanitized URL: Original: $value | Sanitized: $sanitized");
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes an array of strings.
|
||||
*
|
||||
* @param array $values The array of strings to sanitize.
|
||||
* @return array The sanitized array.
|
||||
*/
|
||||
public static function sanitizeArray(array $values): array
|
||||
{
|
||||
$sanitizedArray = filter_var_array($values, FILTER_SANITIZE_STRING);
|
||||
Logger::info("Sanitized array: Original: " . json_encode($values) . " | Sanitized: " . json_encode($sanitizedArray));
|
||||
return $sanitizedArray;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
class StructureGenerator
|
||||
{
|
||||
private array $structure = [
|
||||
'app/Controllers/',
|
||||
'app/Core/',
|
||||
'app/Models/',
|
||||
'app/Services/',
|
||||
'app/Utils/',
|
||||
'app/Interfaces/',
|
||||
'config/',
|
||||
'logs/',
|
||||
'public/assets/css/',
|
||||
'public/assets/js/',
|
||||
'resources/views/layouts/',
|
||||
'resources/views/pages/services/',
|
||||
'resources/views/partials/',
|
||||
'resources/emails/',
|
||||
'scripts/',
|
||||
'storage/cache/',
|
||||
'storage/uploads/',
|
||||
'tests/Controllers/',
|
||||
'tests/Models/',
|
||||
'tests/Utils/',
|
||||
'vendor/'
|
||||
];
|
||||
|
||||
private array $files = [
|
||||
'.env',
|
||||
'.gitignore',
|
||||
'composer.json',
|
||||
'composer.lock',
|
||||
'README.md',
|
||||
'config/config.php',
|
||||
'logs/app.log',
|
||||
'public/index.php',
|
||||
'public/assets/css/styles.css',
|
||||
'public/assets/js/main.js',
|
||||
'resources/views/layouts/header.php',
|
||||
'resources/views/layouts/footer.php',
|
||||
'resources/views/layouts/main.php',
|
||||
'resources/views/layouts/head.php',
|
||||
'resources/views/pages/home.php',
|
||||
'resources/views/pages/services/it_consulting.php',
|
||||
'resources/views/pages/services/emergency_support.php',
|
||||
'resources/views/pages/services/managed_services.php',
|
||||
'resources/views/pages/services/online_brand_management.php',
|
||||
'resources/views/pages/services/project_management.php',
|
||||
'resources/views/pages/about.php',
|
||||
'resources/views/pages/contact.php',
|
||||
'resources/views/pages/testimonials.php',
|
||||
'resources/views/pages/error.php',
|
||||
'resources/views/partials/navbar.php',
|
||||
'resources/views/partials/sidebar.php',
|
||||
'resources/emails/contact_confirmation.php',
|
||||
'scripts/generate_structure.php',
|
||||
'app/Controllers/HomeController.php',
|
||||
'app/Controllers/ServicesController.php',
|
||||
'app/Controllers/HelpDeskController.php',
|
||||
'app/Controllers/EmergencySupportController.php',
|
||||
'app/Controllers/ClientsController.php',
|
||||
'app/Controllers/ContactController.php',
|
||||
'app/Controllers/AboutController.php',
|
||||
'app/Controllers/TestimonialsController.php',
|
||||
'app/Core/Router.php',
|
||||
'app/Core/View.php',
|
||||
'app/Core/BaseController.php',
|
||||
'app/Models/ServiceModel.php',
|
||||
'app/Models/ContactModel.php',
|
||||
'app/Models/TestimonialModel.php',
|
||||
'app/Models/ClientModel.php',
|
||||
'app/Services/ITConsultingService.php',
|
||||
'app/Services/EmergencySupportService.php',
|
||||
'app/Services/OnlineBrandManagementService.php',
|
||||
'app/Services/ManagedHostingService.php',
|
||||
'app/Services/HelpDeskService.php',
|
||||
'app/Services/ProjectManagementService.php',
|
||||
'app/Utils/Logger.php',
|
||||
'app/Utils/Validator.php',
|
||||
'app/Utils/Mailer.php',
|
||||
'app/Interfaces/ServiceInterface.php',
|
||||
'app/Interfaces/LoggableInterface.php'
|
||||
];
|
||||
|
||||
public function createStructure(string $basePath): void
|
||||
{
|
||||
foreach ($this->structure as $folder) {
|
||||
$path = rtrim($basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $folder;
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0755, true);
|
||||
echo "Created directory: $path\n";
|
||||
} else {
|
||||
echo "Directory already exists: $path\n";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->files as $file) {
|
||||
$filePath = rtrim($basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
|
||||
if (!file_exists($filePath)) {
|
||||
file_put_contents($filePath, $this->getDefaultContent($file));
|
||||
echo "Created file with default content: $filePath\n";
|
||||
} else {
|
||||
$currentContent = file_get_contents($filePath);
|
||||
$defaultContent = $this->getDefaultContent($file);
|
||||
if (trim($currentContent) === '') {
|
||||
file_put_contents($filePath, $defaultContent);
|
||||
echo "Updated empty file with default content: $filePath\n";
|
||||
} elseif (trim($currentContent) === trim($defaultContent)) {
|
||||
echo "File already has default content, no changes made: $filePath\n";
|
||||
} else {
|
||||
echo "File has additional content, no changes made: $filePath\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getDefaultContent(string $file): string
|
||||
{
|
||||
if (preg_match('/app\/(Controllers|Core|Models|Services|Utils|Interfaces)\//', $file)) {
|
||||
$namespace = preg_replace('/app\/(.*?)\//', 'WizdomNetworks\\WizeWeb\\$1', dirname($file));
|
||||
$namespace = str_replace('/', '\\', $namespace);
|
||||
$className = pathinfo($file, PATHINFO_FILENAME);
|
||||
return "<?php\n\nnamespace $namespace;\n\nclass $className\n{\n // Placeholder for future implementation\n}\n";
|
||||
}
|
||||
|
||||
if ($file === '.gitignore') {
|
||||
return "/vendor/\n/logs/\n/storage/\n.env\n";
|
||||
}
|
||||
|
||||
if ($file === '.env') {
|
||||
return "# Application Environment\n" .
|
||||
"# Set the application environment (e.g., development, production)\n" .
|
||||
"APP_ENV=development\n\n" .
|
||||
"# Database Configuration\n" .
|
||||
"# Configure the database connection\n" .
|
||||
"DB_HOST=localhost\n" .
|
||||
"DB_PORT=3306\n" .
|
||||
"DB_NAME=\n" .
|
||||
"DB_USER=\n" .
|
||||
"DB_PASSWORD=\n\n" .
|
||||
"# Mailer Configuration\n" .
|
||||
"# Configure email sending\n" .
|
||||
"MAIL_HOST=\n" .
|
||||
"MAIL_PORT=\n" .
|
||||
"MAIL_USER=\n" .
|
||||
"MAIL_PASSWORD=\n";
|
||||
}
|
||||
|
||||
if ($file === 'README.md') {
|
||||
return "# Project Documentation\n\nThis file will contain project documentation.\n";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
if (PHP_SAPI === 'cli') {
|
||||
global $argc, $argv;
|
||||
if ($argc !== 2) {
|
||||
echo "Usage: php generate_structure.php <path>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$path = $argv[1];
|
||||
$generator = new StructureGenerator();
|
||||
$generator->createStructure($path);
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,235 @@
|
|||
<?php
|
||||
|
||||
namespace WizdomNetworks\WizeWeb\Utils;
|
||||
|
||||
/**
|
||||
* Validator Utility
|
||||
*
|
||||
* Provides methods for validating user input.
|
||||
*/
|
||||
class Validator
|
||||
{
|
||||
/**
|
||||
* Check if a value is not empty.
|
||||
*
|
||||
* @param mixed $value The value to check.
|
||||
* @return bool True if the value is not empty, false otherwise.
|
||||
*/
|
||||
public static function isRequired($value): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Checking if value is required: $value");
|
||||
|
||||
$isValid = !empty($value);
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] Value is required but empty.");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an email address.
|
||||
*
|
||||
* @param string $email The email address to validate.
|
||||
* @return bool True if the email is valid, false otherwise.
|
||||
*/
|
||||
public static function isEmail(string $email): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Validating email address: $email");
|
||||
|
||||
$isValid = filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] Invalid email address: $email");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a URL.
|
||||
*
|
||||
* @param string $url The URL to validate.
|
||||
* @return bool True if the URL is valid, false otherwise.
|
||||
*/
|
||||
public static function isURL(string $url): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Validating URL: $url");
|
||||
|
||||
$isValid = filter_var($url, FILTER_VALIDATE_URL) !== false;
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] Invalid URL: $url");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string matches a given regular expression.
|
||||
*
|
||||
* @param string $string The string to validate.
|
||||
* @param string $pattern The regular expression to match.
|
||||
* @return bool True if the string matches the pattern, false otherwise.
|
||||
*/
|
||||
public static function matchesRegex(string $string, string $pattern): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Validating string against regex: Pattern=$pattern");
|
||||
|
||||
$isValid = preg_match($pattern, $string) === 1;
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] String does not match regex: $string");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string has a minimum length.
|
||||
*
|
||||
* @param string $string The string to check.
|
||||
* @param int $minLength The minimum length.
|
||||
* @return bool True if the string meets the minimum length, false otherwise.
|
||||
*/
|
||||
public static function hasMinLength(string $string, int $minLength): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Checking if string has minimum length: $minLength");
|
||||
|
||||
$isValid = strlen($string) >= $minLength;
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] String is shorter than minimum length: $string");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string has a maximum length.
|
||||
*
|
||||
* @param string $string The string to check.
|
||||
* @param int $maxLength The maximum length.
|
||||
* @return bool True if the string meets the maximum length, false otherwise.
|
||||
*/
|
||||
public static function hasMaxLength(string $string, int $maxLength): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Checking if string has maximum length: $maxLength");
|
||||
|
||||
$isValid = strlen($string) <= $maxLength;
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] String exceeds maximum length: $string");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a string length.
|
||||
*
|
||||
* @param string $input The string to validate.
|
||||
* @param int $min Minimum length.
|
||||
* @param int $max Maximum length.
|
||||
* @return bool True if the string length is valid, false otherwise.
|
||||
*/
|
||||
public static function validateStringLength(string $input, int $min, int $max): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Validating string length: Input='$input', Min=$min, Max=$max");
|
||||
|
||||
$length = strlen($input);
|
||||
$isValid = $length >= $min && $length <= $max;
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] Invalid string length: $length (Expected between $min and $max)");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a boolean value.
|
||||
*
|
||||
* @param mixed $input The input to validate as a boolean.
|
||||
* @return bool True if the input is a valid boolean, false otherwise.
|
||||
*/
|
||||
public static function validateBoolean($input): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Validating boolean input: $input");
|
||||
|
||||
$isValid = is_bool(filter_var($input, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] Invalid boolean input: $input");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a date format.
|
||||
*
|
||||
* @param string $date The date string to validate.
|
||||
* @param string $format The expected date format (e.g., 'Y-m-d').
|
||||
* @return bool True if the date matches the format, false otherwise.
|
||||
*/
|
||||
public static function validateDate(string $date, string $format = 'Y-m-d'): bool
|
||||
{
|
||||
try {
|
||||
Logger::info("[DEBUG] Validating date: $date with format: $format");
|
||||
|
||||
$dateTime = \DateTime::createFromFormat($format, $date);
|
||||
$isValid = $dateTime && $dateTime->format($format) === $date;
|
||||
|
||||
if (!$isValid) {
|
||||
Logger::warning("[WARNING] Invalid date: $date (Expected format: $format)");
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
} catch (\Throwable $e) {
|
||||
ErrorHandler::exception($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "wizdomnetworks/wizeweb",
|
||||
"description": "A PHP project adhering to PSR standards.",
|
||||
"type": "library",
|
||||
"version": "0.1.0",
|
||||
"require": {
|
||||
"phpmailer/phpmailer": "^6.8",
|
||||
"vlucas/phpdotenv": "^5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"squizlabs/php_codesniffer": "^3.7",
|
||||
"friendsofphp/php-cs-fixer": "^3.20"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WizdomNetworks\\WizeWeb\\": "app/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"fix": "php-cs-fixer fix",
|
||||
"lint": "phpcs"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
|
||||
// Placeholder for configuration
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
//set_include_path(__DIR__ . '/../resources/views');
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use WizdomNetworks\WizeWeb\Core\Router;
|
||||
use WizdomNetworks\WizeWeb\Controllers\HomeController;
|
||||
use WizdomNetworks\WizeWeb\Controllers\AboutController;
|
||||
use WizdomNetworks\WizeWeb\Controllers\ContactController;
|
||||
use WizdomNetworks\WizeWeb\Controllers\ServicesController;
|
||||
use WizdomNetworks\WizeWeb\Controllers\TestimonialsController;
|
||||
use WizdomNetworks\WizeWeb\Utils\ClassInspector;
|
||||
use WizdomNetworks\WizeWeb\Utils\ErrorHandler;
|
||||
use WizdomNetworks\WizeWeb\Utils\Logger;
|
||||
|
||||
// Debug all classes in the top-level namespace
|
||||
//ClassInspector::debugTopLevelNamespace();
|
||||
|
||||
$router = new Router();
|
||||
$router->add('', HomeController::class, 'index');
|
||||
$router->add('about', AboutController::class, 'index');
|
||||
$router->add('contact', ContactController::class, 'index');
|
||||
$router->add('testimonials', TestimonialsController::class, 'index');
|
||||
$router->add('services', ServicesController::class, 'index');
|
||||
$router->add('services/it-consulting', ServicesController::class, 'itConsulting');
|
||||
$router->add('services/emergency-support', ServicesController::class, 'emergencySupport');
|
||||
$router->add('services/managed-services', ServicesController::class, 'managedServices');
|
||||
|
||||
// Dispatch the request
|
||||
$router->dispatch($_SERVER['REQUEST_URI']);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
|
||||
// Placeholder for email template
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<footer class="bg-dark text-white py-3 mt-auto">
|
||||
<div class="container text-center">
|
||||
<p>© 2025 WizdomNetworks. All Rights Reserved.</p>
|
||||
<ul class="list-inline">
|
||||
<li class="list-inline-item"><a class="text-white" href="/privacy">Privacy Policy</a></li>
|
||||
<li class="list-inline-item"><a class="text-white" href="/terms">Terms of Service</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Modern IT Consulting Services">
|
||||
<meta name="author" content="WizdomNetworks">
|
||||
<title><?php echo $title ?? 'Welcome'; ?></title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/assets/css/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<header class="bg-light py-3">
|
||||
|
||||
</header>
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php $this->render('layouts/head', $data); ?>
|
||||
</head>
|
||||
<body>
|
||||
<?php $this->render('layouts/header', $data); ?>
|
||||
<?php $this->render('partials/navbar', $data); ?>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<?php $this->render('partials/sidebar', $data); ?>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<!-- Main Page Content -->
|
||||
<?php echo $content ?? ''; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<?php $this->render('partials/contact_form', $data); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<?php $this->render('layouts/footer', $data); ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'About - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>About Wizdom Networks</h1><p>At Wizdom Networks, we specialize in delivering top-notch IT solutions to help your business thrive.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
$title = 'Contact Us - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Get in Touch</h1>
|
||||
<p>We would love to hear from you. Use the form below to send us a message, or reach out via email or phone.</p>
|
||||
<div class="contact-details">
|
||||
<p><strong>Email:</strong> contact@wizdom.ca</p>
|
||||
<p><strong>Phone:</strong> +1-800-123-4567</p>
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
// Add the contact form
|
||||
//$content .= $this->getContactForm($data);
|
||||
|
||||
$this->render('layouts/main', compact('title', 'content'));
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'Error - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Page Not Found</h1><p>The page you are looking for does not exist. Please check the URL or go back to the <a href=\"/\">home page</a>.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
// Debugging: Entry point for home.php
|
||||
error_log("[DEBUG] Entering home.php");
|
||||
|
||||
// Define title and content
|
||||
$title = 'Home - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Welcome to Wizdom Networks</h1>
|
||||
<p>Your trusted partner for IT Consulting and Services.</p>
|
||||
<p><a href="/services" class="btn btn-primary">Explore Our Services</a></p>
|
||||
HTML;
|
||||
|
||||
// Debugging: Log title and content length
|
||||
error_log("[DEBUG] Title: $title");
|
||||
error_log("[DEBUG] Content length: " . strlen($content));
|
||||
|
||||
// Prepare data for rendering
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
];
|
||||
|
||||
// Debugging: Log before rendering main layout
|
||||
error_log("[DEBUG] Rendering main layout with data: " . json_encode($data));
|
||||
|
||||
// Render the main layout
|
||||
$this->render('layouts/main', $data);
|
||||
|
||||
|
||||
// Debugging: Exit point for home.php
|
||||
error_log("[DEBUG] Exiting home.php");
|
||||
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?php $this->render('layouts/main', [
|
||||
'content' => '<h1>Our Services</h1><p>Explore our wide range of IT services designed to meet your business needs.</p>',
|
||||
'title' => $title ?? 'Our Services'
|
||||
]); ?>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'Emergency Support - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Emergency Support</h1><p>We offer 24/7 emergency IT support to ensure your business operations run smoothly.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'It Consulting - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>IT Consulting</h1><p>Our IT consulting services provide businesses with tailored solutions to maximize productivity and efficiency.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'Managed Services - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Managed Services</h1><p>We provide end-to-end managed IT services to keep your business running efficiently.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'Online Brand Management - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Online Brand Management</h1><p>Enhance your online presence with our expert brand management services.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'Project Management - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Project Management</h1><p>Efficient project management to ensure your IT projects are delivered on time and within budget.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
$title = 'Testimonials - Wizdom Networks';
|
||||
$content = <<<HTML
|
||||
<h1>Testimonials</h1><p>Here's what our clients have to say about us.</p>
|
||||
HTML;
|
||||
|
||||
$this->render('layouts/main', $data);
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<div class="contact-form-container">
|
||||
<h4>Contact Us</h4>
|
||||
<form action="/submit-contact" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="name">Name:</label>
|
||||
<input type="text" id="name" name="name" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" id="email" name="email" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="message">Message:</label>
|
||||
<textarea id="message" name="message" class="form-control" required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">Wizdom Networks</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/services">Services</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/about">About</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/contact">Contact</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<aside class="col-md-3 bg-light p-3">
|
||||
<h4>Quick Links</h4>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="/services/it-consulting">IT Consulting</a></li>
|
||||
<li><a href="/services/emergency-support">Emergency Support</a></li>
|
||||
<li><a href="/services/managed-services">Managed Services</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
require_once 'vendor/autoload.php';
|
||||
use WizdomNetworks\WizeWeb\Core\Controller;
|
||||
$controller = new Controller();
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
// Directory structure for subpages and their content
|
||||
$pages = [
|
||||
'home.php' => '<h1>Welcome to Wizdom Networks</h1><p>Your trusted partner for IT Consulting and Services.</p><p><a href="/services" class="btn btn-primary">Explore Our Services</a></p>',
|
||||
'about.php' => '<h1>About Wizdom Networks</h1><p>At Wizdom Networks, we specialize in delivering top-notch IT solutions to help your business thrive.</p>',
|
||||
'contact.php' => '<h1>Contact Us</h1><form method="POST" action="/submit-contact"><div class="mb-3"><label for="name" class="form-label">Your Name</label><input type="text" name="name" id="name" class="form-control" required></div><div class="mb-3"><label for="email" class="form-label">Your Email</label><input type="email" name="email" id="email" class="form-control" required></div><div class="mb-3"><label for="message" class="form-label">Your Message</label><textarea name="message" id="message" class="form-control" rows="5" required></textarea></div><button type="submit" class="btn btn-primary">Send Message</button></form>',
|
||||
'testimonials.php' => '<h1>Testimonials</h1><p>Here\'s what our clients have to say about us.</p>',
|
||||
'error.php' => '<h1>Page Not Found</h1><p>The page you are looking for does not exist. Please check the URL or go back to the <a href=\"/\">home page</a>.</p>',
|
||||
'services/it_consulting.php' => '<h1>IT Consulting</h1><p>Our IT consulting services provide businesses with tailored solutions to maximize productivity and efficiency.</p>',
|
||||
'services/emergency_support.php' => '<h1>Emergency Support</h1><p>We offer 24/7 emergency IT support to ensure your business operations run smoothly.</p>',
|
||||
'services/managed_services.php' => '<h1>Managed Services</h1><p>We provide end-to-end managed IT services to keep your business running efficiently.</p>',
|
||||
'services/online_brand_management.php' => '<h1>Online Brand Management</h1><p>Enhance your online presence with our expert brand management services.</p>',
|
||||
'services/project_management.php' => '<h1>Project Management</h1><p>Efficient project management to ensure your IT projects are delivered on time and within budget.</p>'
|
||||
];
|
||||
|
||||
// Use the agreed directory structure for pages
|
||||
$basePath = realpath(__DIR__ . '/../resources/views/pages');
|
||||
|
||||
if (!$basePath) {
|
||||
die("Error: The base directory for pages does not exist. Please ensure the directory structure is correct.\n");
|
||||
}
|
||||
|
||||
foreach ($pages as $file => $content) {
|
||||
$filePath = $basePath . '/' . $file;
|
||||
$dirPath = dirname($filePath);
|
||||
|
||||
// Ensure the directory exists
|
||||
if (!is_dir($dirPath)) {
|
||||
mkdir($dirPath, 0755, true);
|
||||
echo "Created directory: $dirPath\n";
|
||||
}
|
||||
|
||||
$title = ucwords(str_replace(['_', '.php'], [' ', ''], basename($file))) . ' - Wizdom Networks';
|
||||
|
||||
// Create the PHP file with the correct structure
|
||||
$template = <<<PHP
|
||||
<?php
|
||||
|
||||
\$title = '$title';
|
||||
\$content = <<<HTML
|
||||
$content
|
||||
HTML;
|
||||
|
||||
include '../layouts/main.php';
|
||||
PHP;
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
$currentContent = file_get_contents($filePath);
|
||||
|
||||
// Check if the file already has the correct content
|
||||
if (trim($currentContent) === trim($template)) {
|
||||
echo "File already has correct content: $filePath\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the file has placeholder content, overwrite it
|
||||
echo "File exists with different content. Updating: $filePath\n";
|
||||
} else {
|
||||
echo "Creating new file: $filePath\n";
|
||||
}
|
||||
|
||||
file_put_contents($filePath, $template);
|
||||
echo "Generated or updated: $filePath\n";
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
|
||||
// Placeholder for structure generator
|
||||
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\StructureGenerator;
|
||||
|
||||
if (PHP_SAPI === 'cli') {
|
||||
if ($argc !== 2) {
|
||||
echo "Usage: php run_generator.php <path>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$path = $argv[1];
|
||||
$generator = new StructureGenerator();
|
||||
$generator->createStructure($path);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use WizdomNetworks\WizeWeb\Utils\NamespaceUpdater;
|
||||
|
||||
if (PHP_SAPI === 'cli') {
|
||||
global $argc, $argv;
|
||||
|
||||
if ($argc < 2) {
|
||||
echo "Usage: php update_namespaces.php <path> [<autoload_namespace>]\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$path = $argv[1];
|
||||
$autoloadNamespace = $argv[2] ?? null;
|
||||
|
||||
$updater = new NamespaceUpdater();
|
||||
$updater->updateNamespaces($path, $autoloadNamespace);
|
||||
}
|
||||
Loading…
Reference in New Issue