Skip to content

Conversation

@walmir-silva
Copy link
Contributor

No description provided.

- Created directory structure for KaririCode/Dotenv with src and tests folders.
- Added Contracts: Dotenv, Parser, Loader, TypeCaster.
- Implemented Exceptions: DotenvException, InvalidFileException, InvalidValueException.
- Added Parsers: DefaultParser, StrictParser.
- Created Loaders: FileLoader, ArrayLoader.
- Added Type Casters: BooleanCaster, IntegerCaster, FloatCaster, StringCaster, NullCaster, JsonCaster.
- Created main Dotenv class and DotenvFactory class.
- Added Unit and Integration test files.
- Created README.md with initial setup and usage instructions.
- Created .gitignore file.
- feat(TypeSystem): enhance type handling and detection
- fix(FileLoader): improve error handling
- refactor(Dotenv): better separation of concerns
- fix(interfaces): update TypeCaster and TypeDetector for consistency
- perf(ArrayLoader): optimize performance
- fix(DefaultParser): enhance error handling and performance
- style: add missing type hints and return types
- fix: implement stricter null checks and type comparisons
- fix(JsonDetector): resolve potential issues with JSON parsing
- feat(env): enhance flexibility of helper function
- style: improve code readability and adhere to PSR-12

BREAKING CHANGE: The Dotenv class constructor now requires TypeSystem as a parameter.
- Improve JsonDetector to accurately identify JSON objects and arrays of JSON objects
- Refactor ArrayDetector to focus on detecting arrays of arrays
- Implement StringValidatorTrait for common string validation methods
- Create ArrayParserTrait for shared array parsing functionality
- Update method names across detectors for better clarity and semantic meaning

JsonDetector changes:
- Implement distinct methods for JSON objects and arrays of JSON objects
- Add helper method to distinguish between associative and sequential arrays
- Improve accuracy in detecting complex JSON structures

ArrayDetector changes:
- Refocus detection on arrays of arrays
- Simplify logic using shared trait methods

New Traits:
- StringValidatorTrait: Add methods for string input validation and manipulation
- ArrayParserTrait: Implement shared methods for array parsing and validation
- Add interpolateValue method to DefaultParser
- Update parse method to perform interpolation after initial parsing
- Modify Dotenv class to utilize updated parsing logic

This commit addresses the issue with variable interpolation, specifically
resolving the problem with KARIRI_MAIL_FROM_NAME. The changes include:

- Implementing a new interpolateValue method in DefaultParser to handle
  variable substitution using ${VAR_NAME} syntax
- Updating the parse method to perform interpolation as a separate step
  after all variables are initially parsed
- Adjusting the Dotenv class to work with the new parsing approach
- Update JsonCaster to properly decode JSON strings
- Modify TypeSystem to ensure correct registration of JsonCaster
- Refactor testEnvVariable for accurate JSON type detection

This commit addresses the issue where JSON values were incorrectly
identified as strings and improves overall code quality:

- JsonCaster now correctly decodes JSON and handles errors robustly
- TypeSystem explicitly registers JsonCaster for consistent processing
- testEnvVariable function now accurately detects and reports JSON types

Additional improvements:
- Enhance error handling in JsonCaster using JSON_THROW_ON_ERROR
- Improve TypeSystem constructor with optional dependency injection
- Split testEnvVariable logic into smaller, more focused functions
- Add detailed explanations of component features
- Highlight automatic type detection and casting
- Include examples of basic and advanced usage
- Add information about development setup with Docker and Make
- Provide both English (README.md) and Portuguese (README.pt-br.md) versions

This commit significantly improves the documentation for the KaririCode Dotenv component, making it easier for developers to understand its capabilities and how to use it effectively. The updated READMEs now provide:

- Clear installation instructions
- Detailed explanation of type detection and casting
- Examples of basic and advanced usage
- Instructions for setting up the development environment
- Information about available Make commands for development and testing
@walmir-silva walmir-silva merged commit 308ee97 into main Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants