generateEntity

đŸ“Ļ CalDav\Commands\EntityGenerator

EntityGenerator Class This class is responsible for dynamically generating entity classes based on the structure of Commande.php. It creates PHP classes that extend EntityRepository and include properties and methods for all attributes of the entity.
function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

🔧 __construct

Constructor initializes a new entity generator
function __construct($id_type, $id_obje = null) { try { if (empty($id_type) || !is_numeric($id_type)) { throw new Exception("Invalid parameter: id_type must be a valid number."); } $this->id_type = (int)$id_type; // Only set id_obje if it's provided and valid if ($id_obje !== null) { if (!is_numeric($id_obje)) { throw new Exception("Invalid parameter: id_obje must be a valid number if provided."); } // ... (truncated)

âš™ī¸ Parameters

âš ī¸ Throws


🔧 getDefaultAttributes

Gets a default set of attributes for the given type
function getDefaultAttributes($id_type) { // This is a simplified version that creates some default attributes // In a real implementation, you might want to fetch these from a database or configuration return [ 'Id' => [ 'attribute' => 'id', 'value' => null ], 'Name' => [ 'attribute' => 'name', 'value' => null ], // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Default attributes array

🔧 safeGetObjectAttributes

Safely retrieves object attributes with error handling
function safeGetObjectAttributes($id_type, $id_obje) { try { $attributes = fwc7_data_objet_att('', $id_type, $id_obje); if (!is_array($attributes)) { $this->error_messages[] = "fwc7_data_objet_att returned a non-array result."; return false; } return $attributes; } catch (Exception $e) { $this->error_messages[] = "Error fetching object attributes: " . $e->getMessage(); // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array|false) Array of object attributes or false on failure

🔧 hasErrors

Checks if there were any initialization errors
function hasErrors() { return $this->has_errors; }

â†Šī¸ Returns

(bool) True if there were errors, false otherwise

🔧 getErrorMessages

Gets error messages from initialization
function getErrorMessages() { return $this->error_messages; }

â†Šī¸ Returns

(array) Array of error messages

🔧 get_array_attributes

Returns the formatted array of attributes
function get_array_attributes() { return $this->array_attributes; }

â†Šī¸ Returns

(array) Array of formatted attributes

🔧 get_id_type

Returns the parameter type ID
function get_id_type() { return $this->id_type; }

â†Šī¸ Returns

(int) Parameter type ID

🔧 get_id_obje

Returns the object instance ID
function get_id_obje() { return $this->id_obje; }

â†Šī¸ Returns

(int|null) Object instance ID or null if not set

🔧 getGeneratedClassContent

Returns the generated class content
function getGeneratedClassContent() { return $this->generated_class_content; }

â†Šī¸ Returns

(string|null) The generated class content or null if not generated yet

🔧 generateEntityClass

Generates a PHP class for the entity and stores it in memory
function generateEntityClass($className, $namespace, $id_type) { try { // Sanitize the class name $className = $this->sanitizeClassName($className); // Generate the class content $this->generated_class_content = $this->generateClassContent($className, $namespace, $id_type); return true; } catch (Exception $e) { $this->error_messages[] = "Error generating entity class: " . $e->getMessage(); throw new Exception("Failed to generate entity class: " . $e->getMessage()); } }

âš™ī¸ Parameters

â†Šī¸ Returns

(bool) True on success, false on failure

âš ī¸ Throws


🔧 saveToFile

Saves the generated class content to a file
function saveToFile($outputPath) { if ($this->generated_class_content === null) { throw new Exception("No class content has been generated yet. Call generateEntityClass() first."); } try { // Create the output directory if it doesn't exist $directory = dirname($outputPath); if (!is_dir($directory)) { if (!mkdir($directory, 0755, true)) { throw new Exception("Failed to create directory: $directory"); } // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(bool) True on success, false on failure

âš ī¸ Throws


🔧 sanitizeClassName

Sanitizes a class name to ensure it's a valid PHP class name
function sanitizeClassName($className) { // Remove any characters that aren't valid in PHP class names $sanitized = preg_replace('/[^a-zA-Z0-9_]/', '', $className); // Ensure the name starts with a letter or underscore if (!empty($sanitized) && !preg_match('/^[a-zA-Z_]/', $sanitized)) { $sanitized = '_' . $sanitized; } return $sanitized; }

âš™ī¸ Parameters

â†Šī¸ Returns

(string) Sanitized class name

🔧 sanitizePropertyName

Sanitizes property names to ensure valid PHP variable names
function sanitizePropertyName($property) { // Remove any characters that aren't valid in PHP variable names $sanitized = preg_replace('/[^a-zA-Z0-9_]/', '', $property); // Ensure the name starts with a letter or underscore if (!empty($sanitized) && !preg_match('/^[a-zA-Z_]/', $sanitized)) { $sanitized = '_' . $sanitized; } return $sanitized; }

âš™ī¸ Parameters

â†Šī¸ Returns

(string) Sanitized property name

🔧 format_attributes

Formats attributes into a standardized structure This method processes raw attributes and converts them into a clean, formatted array with unique, sanitized keys. It handles character encoding, removes special characters, and ensures unique property names.
function format_attributes($attributes, $id_type) { if (!is_array($attributes)) { throw new Exception("Invalid attributes parameter: must be an array"); } $result = []; $usedTitles = []; $attributeToTitleMap = []; // Track which titles correspond to which attributes foreach ($attributes as $key => $value) { try { // Safely check if the function exists before calling it if (!function_exists('fwc7_param_objet_get_att') || !function_exists('fwc7_data_att_gettitre')) { // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Formatted attributes array with sanitized keys

âš ī¸ Throws