Skip to content

Commit

Permalink
fixing 4.1 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Dec 18, 2023
1 parent 0528c95 commit 0d202ef
Show file tree
Hide file tree
Showing 62 changed files with 742 additions and 536 deletions.
16 changes: 9 additions & 7 deletions docs/acl.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,13 @@ Wildcards can also be used to do mass matching for roles, components or actions.
$acl->allow('*', '*', 'view');
```

Similarly the above gives access to any role, any component that has the `view` action. In a MVC application, the above is the equivalent of allowing any group to access any controller that exposes a `viewAction`.
Similarly, the above gives access to any role, any component that has the `view` action. In a MVC application, the above is the equivalent of allowing any group to access any controller that exposes a `viewAction`.

> **NOTE**: Please be **VERY** careful when using the `*` wildcard. It is very easy to make a mistake and the wildcard, although it seems convenient, it may allow users to access areas of your application that they are not supposed to. The best way to be 100% sure is to write tests specifically to test the permissions and the ACL. These can be done in the `unit` test suite by instantiating the component and then checking the `isAllowed()` if it is `true` or `false`.
>
> [Codeception][codeception] is the chosen testing framework for Phalcon and there are plenty of tests in our GitHub repository (`tests` folder) to offer guidance and ideas.
{:.alert .alert-danger}
!!! danger "NOTE"

Please be **VERY** careful when using the `*` wildcard. It is very easy to make a mistake and the wildcard, although it seems convenient, it may allow users to access areas of your application that they are not supposed to. The best way to be 100% sure is to write tests specifically to test the permissions and the ACL. These can be done in the `unit` test suite by instantiating the component and then checking the `isAllowed()` if it is `true` or `false`.

There are plenty of tests in our GitHub repository (`tests` folder) to offer guidance and ideas.

```php
$acl->deny('guest', '*', 'view');
Expand Down Expand Up @@ -439,8 +440,9 @@ $acl->isAllowed(
);
```

> **NOTE**:The fourth parameter must be an array. Each array element represents a parameter that your anonymous function accepts. The key of the element is the name of the parameter, while the value is what will be passed as the value of that the parameter of to the function.
{:.alert .alert-info}
!!! info "NOTE"

The fourth parameter must be an array. Each array element represents a parameter that your anonymous function accepts. The key of the element is the name of the parameter, while the value is what will be passed as the value of that the parameter of to the function.

You can also omit to pass the fourth parameter to `isAllowed()` if you wish. The default action for a call to `isAllowed()` without the last parameter is `Acl\Enum::DENY`. To change this behavior, you can make a call to `setNoArgumentsDefaultAction()`:

Expand Down
5 changes: 3 additions & 2 deletions docs/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ class BaseController extends Controller
}
```

> **NOTE** You can also implement the above to a listener and use the `beforeDispatch` event if you wish.
{: .alert .alert-info }
!!! info "NOTE"

You can also implement the above to a listener and use the `beforeDispatch` event if you wish.

and in our controllers we can specify:

Expand Down
10 changes: 6 additions & 4 deletions docs/application-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ php cli.php

In the above example, the `cli.php` is the entry point of our application, while the `src/tasks` directory contains all the task classes that handle each command.

> **NOTE**: Each task file and class **must** be suffixed with `Task`. The default task (if no parameters have been passed) is `MainTask` and the default method to be executed inside a task is `main`
{: .alert .alert-info }
!!! info "NOTE"

Each task file and class **must** be suffixed with `Task`. The default task (if no parameters have been passed) is `MainTask` and the default method to be executed inside a task is `main`

## Bootstrap
As seen above, the entry point of our CLI application is the `cli.php`. In that script, we need to bootstrap our application with relevant services, directives etc. This is similar to the all familiar `index.php` that we use for MVC applications.
Expand Down Expand Up @@ -97,8 +98,9 @@ $loader->register();

Create the Phalcon autoloader and register the namespace to point to the `src/` directory.

> **NOTE**: If you decided to use the Composer autoloader in your `composer.json`, you do not need to register the loader in this application
{: .alert .alert-info }
!!! info "NOTE"

If you decided to use the Composer autoloader in your `composer.json`, you do not need to register the loader in this application

**DI**
```php
Expand Down
55 changes: 33 additions & 22 deletions docs/application-micro.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ Defining routes in a [Phalcon\Mvc\Micro][mvc-micro] application is very easy. Ro
### Activation
Routing is handled by the [Phalcon\Mvc\Router][mvc-router] object.

> **NOTE**: Routes must always start with `/`
{: .alert .alert-warning }
!!! warning "NOTE"

Routes must always start with `/`

Usually, the starting route for an application is `/`, accessed via the `GET` HTTP method:

Expand All @@ -319,8 +320,9 @@ $application->get(
);
```

> **NOTE**: Check our [routing](routing.md) document for more information for the [Phalcon\Mvc\Router][mvc-router]
{: .alert .alert-info }
!!! info "NOTE"

Check our [routing](routing.md) document for more information for the [Phalcon\Mvc\Router][mvc-router]

**Application object**

Expand Down Expand Up @@ -984,8 +986,9 @@ $invoices->get('/delete/{id}', 'deleteAction');
$app->mount($invoices);
```

> **NOTE**: The name that we bind each route has a suffix of `Action`. This is not necessary, your method can be called anything you like.
{: .alert .alert-warning }
!!! warning "NOTE"

The name that we bind each route has a suffix of `Action`. This is not necessary, your method can be called anything you like.

**Methods**

Expand Down Expand Up @@ -1164,8 +1167,9 @@ $app->get(
);
```

> **NOTE**: Check our [routing](routing.md) document for more information for the [Phalcon\Mvc\Router][mvc-router]
{: .alert .alert-info }
!!! info "NOTE"

Check our [routing](routing.md) document for more information for the [Phalcon\Mvc\Router][mvc-router]

### Redirections
You can redirect one matched route to another using the [Phalcon\Http\Response][http-response] object, just like in a full application.
Expand All @@ -1192,8 +1196,9 @@ $app->get('/invoices/view/{id}',
);
```

> **NOTE**: We have to pass the `$app` object in our anonymous function to have access to the `request` object.
{: .alert .alert-info }
!!! info "NOTE"

We have to pass the `$app` object in our anonymous function to have access to the `request` object.

When using controllers as handlers, you can perform the redirect just as easy:

Expand Down Expand Up @@ -1614,8 +1619,9 @@ $app->setEventsManager($manager);
## Middleware
Middleware are classes that can be attached to your application and introduce another layer where business logic can exist. They run sequentially, according to the order they are registered and not only improve maintainability, by encapsulating specific functionality, but also performance. A middleware class can stop execution when a particular business rule has not been satisfied, thus allowing the application to exit early without executing the full cycle of a request.

> **NOTE**: The middleware handled by the Micro application **are not** compatible with [PSR-15][psr-15]. In future versions of Phalcon, the whole HTTP layer will be rewritten to align with PSR-7 and PSR-15.
{: .alert .alert-info }
!!! info "NOTE"

The middleware handled by the Micro application **are not** compatible with [PSR-15][psr-15]. In future versions of Phalcon, the whole HTTP layer will be rewritten to align with PSR-7 and PSR-15.

The presence of a [Phalcon\Events\Manager][events-manager] is essential for middleware to operate, so it has to be registered in our DI container.

Expand All @@ -1628,8 +1634,9 @@ Middleware can be attached to a micro application in 3 different events. Those a
| `after` | After the handler has been executed |
| `finish` | After the response has been sent to the caller |

> **NOTE**: You can attach as many middleware classes as you want in each of the above events. They will be executed sequentially when the relevant event fires.
{: .alert .alert-warning }
!!! warning "NOTE"

You can attach as many middleware classes as you want in each of the above events. They will be executed sequentially when the relevant event fires.

**before**

Expand Down Expand Up @@ -1691,8 +1698,9 @@ $app->after(
```
In the above example, the handler returns an array of data. The `after` event calls `json_encode` on it, thus returning valid JSON.

> **NOTE**: You will need to do a bit more work here to set the necessary headers for JSON. An alternative to the above code would be to use the Response object and `setJsonContent`
{: .alert .alert-info }
!!! info "NOTE"

You will need to do a bit more work here to set the necessary headers for JSON. An alternative to the above code would be to use the Response object and `setJsonContent`

**finish**

Expand Down Expand Up @@ -2170,8 +2178,9 @@ class RequestMiddleware implements MiddlewareInterface

This middleware is responsible for manipulating our response and sending it back to the caller as a JSON string. Therefore we need to attach it to the `after` event of our Micro application.

> **NOTE**: We are going to be using the `call` method for this middleware, since we have nearly executed the whole request cycle.
{: .alert .alert-warning }
!!! warning "NOTE"

We are going to be using the `call` method for this middleware, since we have nearly executed the whole request cycle.

```php
<?php
Expand Down Expand Up @@ -2215,8 +2224,9 @@ class ResponseMiddleware implements MiddlewareInterface
### Models
Models can be used in Micro applications, so long as we instruct the application how it can find the relevant classes with an autoloader.

> **NOTE**: The relevant `db` service must be registered in your DI container.
{: .alert .alert-warning }
!!! warning "NOTE"

The relevant `db` service must be registered in your DI container.

```php
<?php
Expand Down Expand Up @@ -2329,8 +2339,9 @@ $app->get(
);
```

> **NOTE**: The above example uses the [Phalcon\Mvc\View\Simple][mvc-view-simple] component, which uses relative paths instead of controllers and actions. You can use the [Phalcon\Mvc\View][mvc-view] component instead, but to do so you will need to change the parameters passed to `render()`.
{: .alert .alert-warning }
!!! warning "NOTE"

The above example uses the [Phalcon\Mvc\View\Simple][mvc-view-simple] component, which uses relative paths instead of controllers and actions. You can use the [Phalcon\Mvc\View][mvc-view] component instead, but to do so you will need to change the parameters passed to `render()`.

```php
<?php
Expand Down
5 changes: 3 additions & 2 deletions docs/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,9 @@ Assuming that your file was last modified in May 20, the version
<link rel="stylesheet" href="css/bootstrap.css?ver=1558392141">
```

> **NOTE** Using the auto version feature is not recommended for production environments, since Phalcon will need to read the modification time of the asset file for every request. This will result to unnecessary read operations on the file system.
{: .alert .alert-warning }
!!! warning "NOTE"

Using the auto version feature is not recommended for production environments, since Phalcon will need to read the modification time of the asset file for every request. This will result to unnecessary read operations on the file system.

## Improving Performance
There are many ways to optimize processing assets. One method is to allow your web server to handle the assets, thus improving response time. First we need to set up the Assets Manager. We will use a base controller, but you can use the manager anywhere you need to, accessing it from the Di container:
Expand Down
32 changes: 19 additions & 13 deletions docs/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Frequently used data or already processed/calculated data, can be stored in a ca
* You are producing HTML using the same data all the time (same HTML)
* You are accessing database data constantly which does not change often.

> **NOTE** Even after implementing the cache, you should always check the hit ratio of your cache backend over a period of time, to ensure that your cache strategy is optimal.
{: .alert .alert-warning}
!!! warning "NOTE"

Even after implementing the cache, you should always check the hit ratio of your cache backend over a period of time, to ensure that your cache strategy is optimal.

[Phalcon\Cache][cache-cache] components rely on `Phalcon\Storage` components. `Phalcon\Storage` is split into two categories: Serializers and Adapters.

Expand Down Expand Up @@ -189,8 +190,9 @@ class IndexController extends Controller
## Serializers
The `Phalcon\Storage\Serializer` namespace offers classes that implement the [Serializable][serializable] interface and thus expose the `serialize` and `unserialize` methods. The purpose of these classes is to transform the data before saving it to the storage and after retrieving it from the storage.

> **NOTE**: The default serializer for all adapters is `Phalcon\Storage\Serializer\Php` which uses PHP's `serialize` and `unserialize` methods. These methods can suit most applications. However the developer might want to use something more efficient such as [igbinary][igbinary] which is faster and achieves a better compression.
{: .alert .alert-info }
!!! info "NOTE"

The default serializer for all adapters is `Phalcon\Storage\Serializer\Php` which uses PHP's `serialize` and `unserialize` methods. These methods can suit most applications. However the developer might want to use something more efficient such as [igbinary][igbinary] which is faster and achieves a better compression.

The cache adapter can be configured to use a different serializer. The available serializers are:

Expand Down Expand Up @@ -341,8 +343,9 @@ The available methdods are:
| `increment` | Increments a stored number |
| `set` | Stores data in the adapter |

> **NOTE**: The `getAdapter()` method returns the connected adapter. This offers more flexibility to the developer, since it can be used to execute additional methods that each adapter offers. For instance for the `Redis` adapter you can use the `getAdapter()` to obtain the connected object and call `zAdd`, `zRange` and other methods not exposed by the Phalcon adapter.
{: .alert .alert-info }
!!! info "NOTE"

The `getAdapter()` method returns the connected adapter. This offers more flexibility to the developer, since it can be used to execute additional methods that each adapter offers. For instance for the `Redis` adapter you can use the `getAdapter()` to obtain the connected object and call `zAdd`, `zRange` and other methods not exposed by the Phalcon adapter.

To construct one of these objects, you will need to pass a [Phalcon\Storage\SerializerFactory][storage-serializerfactory] object in the constructor and optionally some parameters required for the adapter of your choice. The list of options is outlined below.

Expand Down Expand Up @@ -441,8 +444,9 @@ The above example used a [Phalcon\Storage\SerializerFactory][storage-serializerf

The [igbinary][igbinary] built-in serializer is only available if `igbinary` is present in the target system and [Memcached][memcached] extension is compiled with it.

> **NOTE**: If the `defaultSerializer` or the selected serializer for `Libmemcached` is supported as a built-in serializer (`PHP`, `JSON`, `IGBINARY`), the built-in one will be used, resulting in more speed and less resource utilization.
{: .alert .alert-info }
!!! info "NOTE"

If the `defaultSerializer` or the selected serializer for `Libmemcached` is supported as a built-in serializer (`PHP`, `JSON`, `IGBINARY`), the built-in one will be used, resulting in more speed and less resource utilization.

### `Memory`
This adapter uses the computer's memory to store the data. As all data is stored in memory, there is no persistence, meaning that once the request is completed, the data is lost. This adapter can be used for testing or temporary storage during a particular request. The options available for the constructor are:
Expand Down Expand Up @@ -524,10 +528,11 @@ The above example used a [Phalcon\Storage\SerializerFactory][storage-serializerf

The [igbinary][igbinary] and built-in serializer is only available if `igbinary` is present in the target system and [Redis][redis] extension is compiled with it. The same applies to [msgpack][msgpack] built-in serializer. It is only available if `msgpack` is present in the target system and the [Redis][redis] extension is compiled with it.

> **NOTE**: If the `defaultSerializer` or the selected serializer for `Redis` is supported as a built-in serializer (`NONE`, `PHP`, `IGBINARY`, `MSGPACK`), the built-in one will be used, resulting in more speed and less resource utilization.
{: .alert .alert-info }
!!! info "NOTE"

If the `defaultSerializer` or the selected serializer for `Redis` is supported as a built-in serializer (`NONE`, `PHP`, `IGBINARY`, `MSGPACK`), the built-in one will be used, resulting in more speed and less resource utilization.

**NOTE** `increment` - `decrement`
`increment` - `decrement`

At this point in time there is an issue with `Redis`, where the internal `Redis` serializer does not skip scalar values because it can only store strings. As a result, if you use `increment` after a `set` for a number, will not return a number:

Expand Down Expand Up @@ -560,8 +565,9 @@ This adapter is the simplest to setup since it uses the target system's file sys

If the `storageDir` is not defined a `Phalcon\Storage\Exception` will be thrown.

> **NOTE**: The adapter utilizes logic to store files in separate sub directories based on the name of the key passed, thus avoiding the `too many files in one folder` limit present in Windows or Linux based systems.
{: .alert .alert-info }
!!! info "NOTE"

The adapter utilizes logic to store files in separate sub directories based on the name of the key passed, thus avoiding the `too many files in one folder` limit present in Windows or Linux based systems.

The following example demonstrates how to create a new `Stream` cache adapter, which will use the [Phalcon\Storage\Serializer\Json][storage-serializer-json] serializer and have a default lifetime of 7200. It will store the cached data in `/data/storage/cache`.

Expand Down
10 changes: 6 additions & 4 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,9 @@ $config = $factory->newinstance('ini', $fileName, $params);
```

## Json
> **NOTE**: Requires PHP's `json` extension to be present in the system
{: .alert .alert-info }
!!! info "NOTE"

Requires PHP's `json` extension to be present in the system

JSON is a very popular format, especially when transporting data from your application to the front end or when sending back responses from an API. It can also be used as a storage for configuration data. [Phalcon\Config\Json][json] uses `json_decode()` internally to convert a JSON file to a PHP native array and parse it accordingly.

Expand Down Expand Up @@ -665,8 +666,9 @@ $config = $factory->newinstance('php', $fileName);

## Yaml

> **NOTE**: Requires PHP's yaml extension to be present in the system
{: .alert .alert-info }
!!! info "NOTE"

Requires PHP's yaml extension to be present in the system

Another common file format is YAML. [Phalcon\Config\Yaml][yaml] requires the `yaml` PHP extension to be present in your system. It uses the PHP function [yaml_parse_file][yaml-parse-file] to read these files. The adapter reads a `yaml` file supplied as the first parameter of the constructor, but also accepts a second parameter `callbacks` as an array. The `callbacks` supplies content handlers for YAML nodes. It is an associative array of `tag => callable` mappings.

Expand Down
Loading

0 comments on commit 0d202ef

Please sign in to comment.