Skip to content

Commit

Permalink
Update manual
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Oct 23, 2024
1 parent a17b5ba commit 3bdecbd
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 17 deletions.
35 changes: 29 additions & 6 deletions manual/css/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,54 @@
color: rgb(25, 152, 184);
}
body {
margin: 0;
padding: auto;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
color: #333333;
font-family: Arial, sans-serif; /* Ganti dengan Georgia, Helvetica, atau font lain sesuai kebutuhan */
font-size: 14px; /* Ukuran font */
line-height: 1.5; /* Spasi baris */
color: #333; /* Warna teks */
background-color: #f9f9f9; /* Warna latar belakang */
margin: 0;
}

.articles {
padding: 20px 20px 0 250px;
}

.articles h1{
font-size: 28px;
font-weight: normal;
}

.articles h2{
font-size: 24px;
font-weight: normal;
}

.articles h3{
font-size: 20px;
font-weight: normal;
}

.articles h4{
font-size: 16px;
font-weight: normal;
}

pre {
font-family: 'Courier New', Courier, monospace;
border: 1px solid #DDDDDD;
background-color: #F4F4F4;
width: 100%;
padding: 20px 20px;
padding: 16px 16px;
overflow-x: hidden;
box-sizing: border-box;
overflow: auto;
}

code {
display: inline-block;
background-color: #F4F4F4;
padding: 2px 4px;
background-color: #EEEEEE;
padding: 0px 2px;
border-radius: 1px;
}

Expand Down
33 changes: 29 additions & 4 deletions manual/includes/_environment-variable.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
## Environment Variable

Many application use environment variable to store the config. We can replace the config template with the environment variable. We must set the environment variable to the server before run the application.
Environment variables play a crucial role in modern application development, providing a flexible way to manage configuration settings. Instead of hardcoding values directly into your code, you can utilize environment variables to keep sensitive information secure and maintain a clean separation between your application's logic and its configuration. This approach not only enhances security but also makes your application more portable and easier to manage.



### Benefits of Using Environment Variables

1. **Security**: Sensitive information such as API keys, database credentials, and configuration settings can be kept out of your codebase, reducing the risk of accidental exposure.

2. **Portability**: Environment variables allow you to run the same code across different environments (development, staging, production) without needing to modify the codebase.

3. **Simplicity**: Managing configurations through environment variables simplifies deployment processes, particularly in cloud environments where configurations can be set per instance.

### Example Configuration Using YAML and Environment Variables

Here's a basic example of how you can define application settings using a YAML file that references environment variables.

**Sample YAML Configuration**

```yaml
# config.yml
Expand All @@ -18,7 +31,11 @@ body:

```

Before execute this script, user must set environment variable for `TIRE_DIAMETER`, `TIRE_PRESSURE`, `BODY_LENGTH`, `BODY_WIDTH`, `BODY_HEIGHT`, and `BODY_COLOR` depend on the operating system used.
### Setting Environment Variables

Before running your application, ensure that you have set the appropriate environment variables for `TIRE_DIAMETER`, `TIRE_PRESSURE`, `BODY_LENGTH`, `BODY_WIDTH`, `BODY_HEIGHT`, and `BODY_COLOR` based on the operating system you are using.

**Example PHP Code**

```php
<?php
Expand All @@ -40,6 +57,10 @@ echo $car->getBody()->getColor();

```

**Another Sample YAML Configuration**

In addition to the previous example, here's another configuration file that utilizes environment variables for various settings:

### Create Yaml File

```yaml
Expand Down Expand Up @@ -77,7 +98,7 @@ session:
vocal_guide_instrument: piano
```
### Create Environment Variable
### Setting Up Environment Variables
On Windows, users can directly create environment variables either via the graphical user interface (GUI) or the `setx` command line. PHP can immediately read environment variables after Windows is restarted.

Expand Down Expand Up @@ -117,3 +138,7 @@ echo -e 'SetEnv APP_DATABASE_SALT "GaramDapur"' >> /etc/httpd/conf.d/mpm.conf
service httpd restart
```

### Conclusion

Utilizing environment variables for configuration management is an essential practice for modern application development. By separating configuration from code, you can enhance security, portability, and maintainability. MagicObject’s ability to integrate with environment variables through YAML configuration files allows for a flexible and powerful setup that can adapt to various environments seamlessly. This approach empowers developers to build more secure and robust applications while simplifying deployment and management processes.
44 changes: 44 additions & 0 deletions manual/includes/_object-from-ini.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
## Object from INI


When working with configuration files, the INI format is a popular choice due to its simplicity and readability. However, PHP's native INI parsing functions come with significant limitations, particularly concerning reserved words. These restrictions can hinder developers' ability to create flexible and user-defined content in INI files. To address this issue, MagicObject has developed its own custom INI parser, providing greater freedom and functionality.

### The Limitations of Native INI Parsing in PHP

PHP's built-in functions for parsing INI files, such as `parse_ini_file()`, are convenient but have notable drawbacks:

1. **Reserved Words**: PHP defines certain keywords as reserved words, which cannot be used as keys in INI files. This limitation can frustrate developers who want to use these words in their configuration settings.

2. **Data Types**: The native parser treats all values as strings, making it difficult to handle different data types without additional processing.

3. **Error Handling**: The native functions offer limited error reporting, making it challenging to debug issues in INI files.

4. **Lack of Flexibility**: PHP’s native INI parser does not support advanced features like sections or comments beyond basic syntax, which can be a hindrance for complex configurations.


### The MagicObject Solution

To provide developers with a more robust and flexible solution, MagicObject introduces its own custom INI parser. Here are some of the benefits of using MagicObject's INI parser:

**1. Freedom from Reserved Words**

One of the most significant advantages of the custom parser is its ability to handle reserved words. Developers can define keys in their INI files without worrying about conflicts with PHP's reserved keywords, leading to greater flexibility in configuration design.

**2. Enhanced Data Type Support**

MagicObject's INI parser can intelligently handle various data types. This means that values can be parsed as integers, booleans, or arrays, reducing the need for manual type conversion after reading the configuration.

**3. Comprehensive Error Handling**

The custom parser includes robust error handling features, providing detailed feedback when issues arise. This improved debugging capability allows developers to quickly identify and resolve problems in their INI files.

**4. Advanced Features**

The MagicObject INI parser supports advanced features such as:

- **Nested Sections**: Allowing developers to create hierarchical configurations.
- **Comments**: Supporting inline comments to enhance readability and maintainability.
- **Dynamic Keys**: Enabling the creation of dynamic keys that can change based on specific conditions.

**5. Improved Performance**

The custom parser is optimized for performance, ensuring that reading and processing INI files is efficient, even for larger configurations. This enhancement is crucial for applications that rely on quick access to configuration settings.

INI not support multilevel object. If multilevel object needed, use Yaml instead.

### From INI String
Expand Down
61 changes: 58 additions & 3 deletions manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,40 @@ <h3>From Yaml File</h3>

<article class="article" id="part8">
<h2>Object from INI</h2>
<p>When working with configuration files, the INI format is a popular choice due to its simplicity and readability. However, PHP's native INI parsing functions come with significant limitations, particularly concerning reserved words. These restrictions can hinder developers' ability to create flexible and user-defined content in INI files. To address this issue, MagicObject has developed its own custom INI parser, providing greater freedom and functionality.</p>
<h3>The Limitations of Native INI Parsing in PHP</h3>
<p>PHP's built-in functions for parsing INI files, such as <code>parse_ini_file()</code>, are convenient but have notable drawbacks:</p>
<ol>
<li>
<p><strong>Reserved Words</strong>: PHP defines certain keywords as reserved words, which cannot be used as keys in INI files. This limitation can frustrate developers who want to use these words in their configuration settings.</p>
</li>
<li>
<p><strong>Data Types</strong>: The native parser treats all values as strings, making it difficult to handle different data types without additional processing.</p>
</li>
<li>
<p><strong>Error Handling</strong>: The native functions offer limited error reporting, making it challenging to debug issues in INI files.</p>
</li>
<li>
<p><strong>Lack of Flexibility</strong>: PHP’s native INI parser does not support advanced features like sections or comments beyond basic syntax, which can be a hindrance for complex configurations.</p>
</li>
</ol>
<h3>The MagicObject Solution</h3>
<p>To provide developers with a more robust and flexible solution, MagicObject introduces its own custom INI parser. Here are some of the benefits of using MagicObject's INI parser:</p>
<p><strong>1. Freedom from Reserved Words</strong></p>
<p>One of the most significant advantages of the custom parser is its ability to handle reserved words. Developers can define keys in their INI files without worrying about conflicts with PHP's reserved keywords, leading to greater flexibility in configuration design.</p>
<p><strong>2. Enhanced Data Type Support</strong></p>
<p>MagicObject's INI parser can intelligently handle various data types. This means that values can be parsed as integers, booleans, or arrays, reducing the need for manual type conversion after reading the configuration.</p>
<p><strong>3. Comprehensive Error Handling</strong></p>
<p>The custom parser includes robust error handling features, providing detailed feedback when issues arise. This improved debugging capability allows developers to quickly identify and resolve problems in their INI files.</p>
<p><strong>4. Advanced Features</strong></p>
<p>The MagicObject INI parser supports advanced features such as:</p>
<ul>
<li><strong>Nested Sections</strong>: Allowing developers to create hierarchical configurations.</li>
<li><strong>Comments</strong>: Supporting inline comments to enhance readability and maintainability.</li>
<li><strong>Dynamic Keys</strong>: Enabling the creation of dynamic keys that can change based on specific conditions.</li>
</ul>
<p><strong>5. Improved Performance</strong></p>
<p>The custom parser is optimized for performance, ensuring that reading and processing INI files is efficient, even for larger configurations. This enhancement is crucial for applications that rely on quick access to configuration settings.</p>
<p>INI not support multilevel object. If multilevel object needed, use Yaml instead.</p>
<h3>From INI String</h3>
<pre><code class="language-php">&lt;?php
Expand Down Expand Up @@ -586,7 +620,22 @@ <h3>From INI File</h3>

<article class="article" id="part9">
<h2>Environment Variable</h2>
<p>Many application use environment variable to store the config. We can replace the config template with the environment variable. We must set the environment variable to the server before run the application.</p>
<p>Environment variables play a crucial role in modern application development, providing a flexible way to manage configuration settings. Instead of hardcoding values directly into your code, you can utilize environment variables to keep sensitive information secure and maintain a clean separation between your application's logic and its configuration. This approach not only enhances security but also makes your application more portable and easier to manage.</p>
<h3>Benefits of Using Environment Variables</h3>
<ol>
<li>
<p><strong>Security</strong>: Sensitive information such as API keys, database credentials, and configuration settings can be kept out of your codebase, reducing the risk of accidental exposure.</p>
</li>
<li>
<p><strong>Portability</strong>: Environment variables allow you to run the same code across different environments (development, staging, production) without needing to modify the codebase.</p>
</li>
<li>
<p><strong>Simplicity</strong>: Managing configurations through environment variables simplifies deployment processes, particularly in cloud environments where configurations can be set per instance.</p>
</li>
</ol>
<h3>Example Configuration Using YAML and Environment Variables</h3>
<p>Here's a basic example of how you can define application settings using a YAML file that references environment variables.</p>
<p><strong>Sample YAML Configuration</strong></p>
<pre><code class="language-yaml"># config.yml

tire:
Expand All @@ -598,7 +647,9 @@ <h2>Environment Variable</h2>
height: ${BODY_HEIGHT}
color: ${BODY_COLOR}
</code></pre>
<p>Before execute this script, user must set environment variable for <code>TIRE_DIAMETER</code>, <code>TIRE_PRESSURE</code>, <code>BODY_LENGTH</code>, <code>BODY_WIDTH</code>, <code>BODY_HEIGHT</code>, and <code>BODY_COLOR</code> depend on the operating system used.</p>
<h3>Setting Environment Variables</h3>
<p>Before running your application, ensure that you have set the appropriate environment variables for <code>TIRE_DIAMETER</code>, <code>TIRE_PRESSURE</code>, <code>BODY_LENGTH</code>, <code>BODY_WIDTH</code>, <code>BODY_HEIGHT</code>, and <code>BODY_COLOR</code> based on the operating system you are using.</p>
<p><strong>Example PHP Code</strong></p>
<pre><code class="language-php">&lt;?php
use MagicObject\MagicObject;

Expand All @@ -616,6 +667,8 @@ <h2>Environment Variable</h2>

echo $car-&gt;getBody()-&gt;getColor();
</code></pre>
<p><strong>Another Sample YAML Configuration</strong></p>
<p>In addition to the previous example, here's another configuration file that utilizes environment variables for various settings:</p>
<h3>Create Yaml File</h3>
<pre><code class="language-yaml">result_per_page: 20
song_base_url: ${SONG_BASE_URL}
Expand Down Expand Up @@ -649,7 +702,7 @@ <h3>Create Yaml File</h3>
name: MUSICPRODUCTIONMANAGER
max_life_time: 86400
vocal_guide_instrument: piano</code></pre>
<h3>Create Environment Variable</h3>
<h3>Setting Up Environment Variables</h3>
<p>On Windows, users can directly create environment variables either via the graphical user interface (GUI) or the <code>setx</code> command line. PHP can immediately read environment variables after Windows is restarted.</p>
<p>On Linux, users must create a configuration on the Apache server by creating a file with the .conf extension in the <code>/etc/httpd/conf.d</code> folder then restart Apache web server.</p>
<p><strong>Windows</strong></p>
Expand Down Expand Up @@ -677,6 +730,8 @@ <h3>Create Environment Variable</h3>
echo -e 'SetEnv APP_DATABASE_SALT "GaramDapur"' &gt;&gt; /etc/httpd/conf.d/mpm.conf

service httpd restart</code></pre>
<h3>Conclusion</h3>
<p>Utilizing environment variables for configuration management is an essential practice for modern application development. By separating configuration from code, you can enhance security, portability, and maintainability. MagicObject’s ability to integrate with environment variables through YAML configuration files allows for a flexible and powerful setup that can adapt to various environments seamlessly. This approach empowers developers to build more secure and robust applications while simplifying deployment and management processes.</p>
</article>

<article class="article" id="part10">
Expand Down
Loading

0 comments on commit 3bdecbd

Please sign in to comment.