4 |
5 | Official [Phalcon][0] documentation website.
6 |
7 | ## Documentation
8 | * Official documentation is [located here][1]
9 |
10 | ## Community
11 | * Follow us on [GitHub][3], [Facebook][4], [Twitter][5] or [Gab.ai][6]
12 | * Get Phalcon support on [Discord][7] and [Official Discussions][8]
13 |
14 | ## Contributing
15 |
16 | This work is an open source, community-driven project. See [CONTRIBUTING.md][9]
17 | for details about contributions to this repository.
18 |
19 |
20 | ## Sponsors
21 |
22 | Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/phalcon#sponsor)]
23 |
24 |
25 |
26 |
27 |
28 | ## Backers
29 |
30 | Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/phalcon#backer)]
31 |
32 |
33 |
34 |
35 |
36 |
37 | ## License
38 |
39 | This work licensed under the New BSD License. See the [LICENSE][10] file for more information.
40 |
41 | [0]: https://phalcon.io
42 | [1]: https://docs.phalcon.io
43 | [3]: https://github.com/phalcon/cphalcon
44 | [4]: https://phalcon.io/fb
45 | [5]: https://phalcon.io/t
46 | [6]: https://phalcon.io/gab
47 | [7]: https://phalcon.io/discord
48 | [8]: https://phalcon.io/discussions
49 | [9]: https://github.com/phalcon/cphalcon/blob/master/CONTRIBUTING.md
50 | [10]: https://github.com/phalcon/cphalcon/blob/master/LICENSE.txt
51 |
--------------------------------------------------------------------------------
/docs/new-feature-request.md:
--------------------------------------------------------------------------------
1 | # New Feature Request
2 | - - -
3 |
4 | [List of NFRs][new-feature-request-list]
5 |
6 | A NFR is a short document explaining how a new feature request must be submitted, how it can be implemented, and how it can help core developers and others to understand and implement it.
7 |
8 | A NFR contains:
9 |
10 | * Suggested syntax
11 | * Suggested class names and methods
12 | * A description detailing the usage
13 | * How it can benefit the framework and the community
14 | * If the feature is already implemented in other frameworks, a short explanation of how that was implemented and its advantages
15 |
16 | In the following cases a new feature request will be rejected **if**:
17 |
18 | * The feature makes the framework slow
19 | * The feature does not provide any additional value to the framework
20 | * The NFR is not clear, bad documentation, unclear explanation, etc.
21 | * The NFR has not been discussed with the Team or voted by the community
22 | * The NFR does not follow the current guidelines/philosophy of the framework
23 | * The NFR affects/breaks applications developed in current/older versions of the framework
24 | * The original poster does not provide feedback/input when requested
25 | * It's technically impossible to implement
26 | * It can only be used in the development/testing stages
27 | * Submitted/proposed classes/components don't follow the [Single Responsibility Principle][srp]
28 | * Uses static methods - (not allowed)
29 |
30 | To send a NFR you do not need to provide Zephir or C code or develop the feature. New Feature requests explain the goal of the intended implementation and start a discussion on how best to implement it.
31 |
32 | All NFRs should be posted as a new issue on [GitHub][issues]. Please make sure to use the prefix `[NFR]` in the title of your issue.
33 |
34 | [new-feature-request-list]: new-feature-request-list.md
35 | [srp]: https://en.wikipedia.org/wiki/Single_responsibility_principle
36 | [issues]: https://github.com/phalcon/cphalcon/issues
37 |
--------------------------------------------------------------------------------
/docs/assets/images/icons/github-icon.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/mvc.md:
--------------------------------------------------------------------------------
1 | # MVC - Model View Controller
2 | - - -
3 |
4 | ## Overview
5 | Model View Controller ([MVC][wiki-mvc]) is a software architectural pattern, which divides the application logic into three interconnected elements, separating internal representations of information of the application.
6 |
7 | Phalcon offers the object-oriented classes, necessary to implement the Model View Controller in your application. This design pattern is widely used by other web frameworks and desktop applications.
8 |
9 | MVC benefits include:
10 |
11 | * Isolation of business logic from the user interface and the database layer
12 | * Making it clear where different types of code belong for easier maintenance
13 |
14 | If you decide to use MVC, every request to your application resources will be managed by the MVC architecture. Phalcon classes are written in Zephir, which is translated to C, offering a high performance implementation of the MVC pattern in PHP applications.
15 |
16 | ## Models
17 | A model represents the information (data) of the application and the rules to manipulate that data. Models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, each table in your database will correspond to one model in your application. The bulk of your application's business logic will be concentrated in the models. [more...][db-models]
18 |
19 | ## Views
20 | Views represent the user interface of your application. Views are often HTML files with embedded PHP code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application. [more...][views]
21 |
22 | ## Controllers
23 | The controllers provide the _flow_ between models and views. Controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation. [more...][controllers]
24 |
25 | [wiki-mvc]: https://en.wikipedia.org/wiki/Model–view–controller
26 | [db-models]: db-models.md
27 | [views]: views.md
28 | [controllers]: controllers.md
29 |
--------------------------------------------------------------------------------
/.github/workflows/deploy-documents.yml:
--------------------------------------------------------------------------------
1 | name: Deploy Documents
2 |
3 | env:
4 | PYTHON_VERSION: "3.9"
5 |
6 | on:
7 | push:
8 | branches:
9 | # Branch to base "dev" website on. Set in siteversion.py also.
10 | - master
11 | # Release branches have names like 0.8.x, 0.9.x, ...
12 | - "[0-9]+.[0-9]+.x"
13 | create:
14 |
15 | jobs:
16 | pre-publish:
17 | runs-on: ubuntu-latest
18 | outputs:
19 | result: ${{ steps.determination.outputs.result }}
20 | steps:
21 | - name: Determine if documentation should be published on this workflow run
22 | id: determination
23 | run: |
24 | RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
25 | if [[ "${{ github.event_name }}" == "push" || ( "${{ github.event_name }}" == "create" && "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX ) ]]; then
26 | RESULT="true"
27 | else
28 | RESULT="true"
29 | fi
30 |
31 | echo "result=$RESULT" >> $GITHUB_OUTPUT
32 |
33 | publish:
34 | runs-on: ubuntu-latest
35 | needs: pre-publish
36 | if: needs.publish-determination.outputs.result == 'true'
37 |
38 | steps:
39 | - name: Checkout repository
40 | uses: actions/checkout@v4
41 |
42 | - name: Install Python
43 | uses: actions/setup-python@v5
44 | with:
45 | python-version: ${{ env.PYTHON_VERSION }}
46 |
47 | - name: Install Requirements
48 | run: |
49 | python -m pip install --upgrade pip
50 | python -m pip install -r requirements.txt
51 |
52 | - name: Create all generated documentation content
53 | run: mkdocs build
54 |
55 | - name: Determine versioning parameters
56 | id: determine-versioning
57 | run: echo "data={"version":"5.4.0", "alias"="latest"}" >> $GITHUB_OUTPUT
58 |
59 | - name: Deploy
60 | if: fromJson(steps.determine-versioning.outputs.data).version != null
61 | run: |
62 | # Publishing implies creating a git commit on the gh-pages branch, we let @ArduinoBot own these commits.
63 | git config --global user.email "deploy@phalcon.io"
64 | git config --global user.name "Phalcon Team Deploy Bot"
65 | git fetch --no-tags --prune --depth=1 origin +refs/heads/production:refs/remotes/origin/production
66 | poetry run mike deploy \
67 | --update-aliases \
68 | --push \
69 | --remote origin \
70 | ${{ fromJson(steps.determine-versioning.outputs.data).version }} \
71 | ${{ fromJson(steps.determine-versioning.outputs.data).alias }}
72 |
--------------------------------------------------------------------------------
/docs/assets/images/version-3.4.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/assets/images/version-4.0.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/api/phalcon_factory.md:
--------------------------------------------------------------------------------
1 |
2 | * [Phalcon\Factory\AbstractConfigFactory](#factory-abstractconfigfactory)
3 | * [Phalcon\Factory\AbstractFactory](#factory-abstractfactory)
4 | * [Phalcon\Factory\Exception](#factory-exception)
5 |
6 |
Abstract Class Phalcon\Factory\AbstractConfigFactory
7 |
8 | [Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/Factory/AbstractConfigFactory.zep)
9 |
10 | | Namespace | Phalcon\Factory |
11 | | Uses | Phalcon\Config\ConfigInterface |
12 |
13 | This file is part of the Phalcon Framework.
14 |
15 | (c) Phalcon Team
16 |
17 | For the full copyright and license information, please view the LICENSE.txt
18 | file that was distributed with this source code.
19 |
20 |
21 | ## Methods
22 |
23 | ```php
24 | protected function checkConfig( mixed $config ): array;
25 | ```
26 | Checks the config if it is a valid object
27 |
28 |
29 | ```php
30 | protected function checkConfigElement( array $config, string $element ): array;
31 | ```
32 | Checks if the config has "adapter"
33 |
34 |
35 | ```php
36 | protected function getException( string $message ): \Exception;
37 | ```
38 | Returns the exception object for the child class
39 |
40 |
41 | ```php
42 | protected function getExceptionClass(): string;
43 | ```
44 |
45 |
46 |
47 |
48 |
49 |
Abstract Class Phalcon\Factory\AbstractFactory
50 |
51 | [Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/Factory/AbstractFactory.zep)
52 |
53 | | Namespace | Phalcon\Factory |
54 | | Uses | Phalcon\Config\ConfigInterface |
55 | | Extends | AbstractConfigFactory |
56 |
57 | This file is part of the Phalcon Framework.
58 |
59 | (c) Phalcon Team
60 |
61 | For the full copyright and license information, please view the LICENSE.txt
62 | file that was distributed with this source code.
63 |
64 |
65 | ## Properties
66 | ```php
67 | /**
68 | * @var array
69 | */
70 | protected mapper;
71 |
72 | /**
73 | * @var array
74 | */
75 | protected services;
76 |
77 | ```
78 |
79 | ## Methods
80 |
81 | ```php
82 | protected function getService( string $name ): mixed;
83 | ```
84 | Checks if a service exists and throws an exception
85 |
86 |
87 | ```php
88 | abstract protected function getServices(): array;
89 | ```
90 | Returns the adapters for the factory
91 |
92 |
93 | ```php
94 | protected function init( array $services = [] ): void;
95 | ```
96 | Initialize services/add new services
97 |
98 |
99 |
100 |
101 |
Class Phalcon\Factory\Exception
102 |
103 | [Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/Factory/Exception.zep)
104 |
105 | | Namespace | Phalcon\Factory |
106 | | Extends | \Exception |
107 |
108 | This file is part of the Phalcon Framework.
109 |
110 | (c) Phalcon Team
111 |
112 | For the full copyright and license information, please view the LICENSE.txt
113 | file that was distributed with this source code.
114 |
--------------------------------------------------------------------------------
/docs/api/phalcon_application.md:
--------------------------------------------------------------------------------
1 |
2 | * [Phalcon\Application\AbstractApplication](#application-abstractapplication)
3 | * [Phalcon\Application\Exception](#application-exception)
4 |
5 |
Abstract Class Phalcon\Application\AbstractApplication
6 |
7 | [Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/Application/AbstractApplication.zep)
8 |
9 | | Namespace | Phalcon\Application |
10 | | Uses | Phalcon\Di\DiInterface, Phalcon\Di\Injectable, Phalcon\Events\EventsAwareInterface, Phalcon\Events\ManagerInterface |
11 | | Extends | Injectable |
12 | | Implements | EventsAwareInterface |
13 |
14 | Base class for Phalcon\Cli\Console and Phalcon\Mvc\Application.
15 |
16 |
17 | ## Properties
18 | ```php
19 | /**
20 | * @var DiInterface|null
21 | */
22 | protected container;
23 |
24 | /**
25 | * @var string
26 | */
27 | protected defaultModule = "";
28 |
29 | /**
30 | * @var ManagerInterface|null
31 | */
32 | protected eventsManager;
33 |
34 | /**
35 | * @var array
36 | */
37 | protected modules;
38 |
39 | ```
40 |
41 | ## Methods
42 |
43 | ```php
44 | public function __construct( DiInterface $container = null );
45 | ```
46 | Phalcon\AbstractApplication constructor
47 |
48 |
49 | ```php
50 | public function getDefaultModule(): string;
51 | ```
52 | Returns the default module name
53 |
54 |
55 | ```php
56 | public function getEventsManager(): ManagerInterface | null;
57 | ```
58 | Returns the internal event manager
59 |
60 |
61 | ```php
62 | public function getModule( string $name ): array | object;
63 | ```
64 | Gets the module definition registered in the application via module name
65 |
66 |
67 | ```php
68 | public function getModules(): array;
69 | ```
70 | Return the modules registered in the application
71 |
72 |
73 | ```php
74 | public function registerModules( array $modules, bool $merge = bool ): AbstractApplication;
75 | ```
76 | Register an array of modules present in the application
77 |
78 | ```php
79 | $this->registerModules(
80 | [
81 | "frontend" => [
82 | "className" => \Multiple\Frontend\Module::class,
83 | "path" => "../apps/frontend/Module.php",
84 | ],
85 | "backend" => [
86 | "className" => \Multiple\Backend\Module::class,
87 | "path" => "../apps/backend/Module.php",
88 | ],
89 | ]
90 | );
91 | ```
92 |
93 |
94 | ```php
95 | public function setDefaultModule( string $defaultModule ): AbstractApplication;
96 | ```
97 | Sets the module name to be used if the router doesn't return a valid module
98 |
99 |
100 | ```php
101 | public function setEventsManager( ManagerInterface $eventsManager ): void;
102 | ```
103 | Sets the events manager
104 |
105 |
106 |
107 |
108 |
Class Phalcon\Application\Exception
109 |
110 | [Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/Application/Exception.zep)
111 |
112 | | Namespace | Phalcon\Application |
113 | | Extends | \Exception |
114 |
115 | Exceptions thrown in Phalcon\Application class will use this class
116 |
--------------------------------------------------------------------------------
/docs/new-pull-request.md:
--------------------------------------------------------------------------------
1 | # New Pull Request
2 | - - -
3 |
4 | A pull request for Phalcon must be against our main repository [cphalcon][cphalcon]. It is a collection of changes to the code that:
5 |
6 | - fix a bug (current issue)
7 | - introduce new functionality or enhancement.
8 |
9 | Your pull request must include:
10 |
11 | * Target the correct branch.
12 | * Update the relevant `CHANGELOG.md`
13 | * Contain unit tests
14 | * Updates to the documentation and usage examples as necessary
15 | * Your code must abide by the coding standards that Phalcon uses. For PHP code we use [PSR-12][psr-12] while for Zephir code, we have an `.editorconfig` file available at the root of the repository to help you follow the standards.
16 |
17 | !!! danger "NOTE"
18 |
19 | **We do not accept Pull Requests to the `master` branch**
20 |
21 | If your pull request relates to fixing an issue/bug, please link the issue number in the pull request body. You can utilize the template we have in GitHub to present this information. If no issue exists, please create one.
22 |
23 | For new functionality, **we will need to have an issue created and referenced**. If the functionality you are introducing collides with the philosophy and implementation of Phalcon, the pull request will be rejected.
24 |
25 | Additionally, any new functionality that introduces breaking changes will not be accepted for the current release but instead will need to be updated to target the next major version.
26 |
27 | It is highly recommended to discuss your NFR and PR with the core team and most importantly with the community to get feedback, guidance and to work on a release plan that will benefit everyone.
28 |
29 | ## Branch and Commits
30 | The following steps are recommended but not mandatory.
31 |
32 | If you are working on an issue, note the number of the issue down. Let us assume that the issue is:
33 |
34 | `#12345 - Create New Object`
35 |
36 | - Checkout the `5.0.x` branch
37 | - Create a branch: `T12345-create-new-object`
38 |
39 | The name of the branch starts with `T`, followed by the number of the issue and then the title of the issue as a slug.
40 |
41 | In your `cphalcon` folder navigate to `.git/hooks`
42 |
43 | Create a new file called `commit-msg` and paste the code below in it and save it:
44 |
45 | ```bash
46 | #!/bin/bash
47 | if [ -z "$BRANCHES_TO_SKIP" ]; then
48 | BRANCHES_TO_SKIP=(master develop)
49 | fi
50 | BRANCH_NAME=$(git symbolic-ref --short HEAD)
51 | BRANCH_NAME="${BRANCH_NAME##*/}"
52 | BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
53 | BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)
54 | if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
55 | ISSUE="$(echo $BRANCH_NAME | cut -d'-' -f 1)"
56 | ISSUE="${ISSUE/T/#}"
57 | sed -i.bak -e "1s/^/[$ISSUE] - /" $1
58 | fi
59 | ```
60 |
61 | Ensure that the file is executable
62 |
63 | ```bash
64 | chmod a+x commit-msg
65 | ```
66 |
67 | Any commits you add now to your branch will appear tied to the `12345` issue.
68 |
69 | Doing the above allows everyone to see which commits relate to which issue.
70 |
71 | [cphalcon]: https://github.com/phalcon/cphalcon
72 | [psr-12]: https://www.php-fig.org/psr/psr-12/
73 |
--------------------------------------------------------------------------------
/docs/html-breadcrumbs.md:
--------------------------------------------------------------------------------
1 | # HTML Components
2 | - - -
3 |
4 | ## Overview
5 | A common piece of HTML that is present in many web applications is the breadcrumbs. These are links separated by a space or by the `/` character usually, that represent the tree structure of an application. The purpose is to give users another easy visual way to navigate throughout the application.
6 |
7 | An example is an application that has an `admin` module, an `invoices` area and a `view invoice` page. Usually, you would select the `admin` module, then from the links you will choose `invoices` (list) and then clicking on one of the invoices in the list, you can view it. To represent this tree like structure, the breadcrumbs displayed could be:
8 |
9 | ```php
10 | Home / Admin / Invoices / Viewing Invoice [1234]
11 | ```
12 | Each of the words above (apart from the last one) are links to the respective pages. This way the user can quickly navigate back to a different area without having to click the back button or use another menu.
13 |
14 | [Phalcon\Html\Breadcrumbs][html-breadcrumbs] offers functionality to add text and URLs. The resulting HTML when calling `render()` will have each breadcrumb enclosed in `
` tags, while the whole string is enclosed in `
` tags.
15 |
16 | ### Methods
17 | ```php
18 | public function add(
19 | string $label,
20 | string $link = ""
21 | ): Breadcrumbs
22 | ```
23 | Adds a new crumb.
24 |
25 | In the example below, add a crumb with a link and then add a crumb without a link (normally the last one)
26 |
27 | ```php
28 | $breadcrumbs
29 | ->add("Home", "/")
30 | ->add("Users")
31 | ;
32 | ```
33 |
34 | ```php
35 | public function clear(): void
36 | ```
37 | Clears the crumbs
38 |
39 | ```php
40 | $breadcrumbs->clear()
41 | ```
42 |
43 | ```php
44 | public function getSeparator(): string
45 | ```
46 | Returns the separator used for the breadcrumbs
47 |
48 | ```php
49 | public function remove(string $link): void
50 | ```
51 | Removes crumb by url.
52 |
53 | In the example below remove a crumb by URL and also remove a crumb without an url (last link)
54 |
55 | ```php
56 | $breadcrumbs->remove("/admin/user/create");
57 | $breadcrumbs->remove();
58 | ```
59 |
60 | ```php
61 | public function render(): string
62 | ```
63 | Renders and outputs breadcrumbs HTML. The template used is:
64 |
65 | ```html
66 |
71 | ```
72 | The last set crumb will not have a link and will only have its text displayed. Each crumb is wrapped in `` tags. The whole collection is wrapped in `
` tags. You can use them in conjunction with CSS to format the crumbs on screen according to the needs of your application.
73 |
74 | ```php
75 | echo $breadcrumbs->render();
76 | ```
77 |
78 | ```php
79 | public function setSeparator(string $separator)
80 | ```
81 | The default separator between the crumbs is `/`. You can set a different one if you wish using this method.
82 |
83 | ```php
84 | $breadcrumbs->setSeparator('-');
85 | ```
86 |
87 | ```php
88 | public function toArray(): array
89 | ```
90 | Returns the internal breadcrumbs array
91 |
92 | [html-breadcrumbs]: api/phalcon_html.md#html-breadcrumbs
93 | [html-exception]: api/phalcon_html.md#html-exception
94 | [html-tagfactory]: api/phalcon_html.md#html-tagfactory
95 |
--------------------------------------------------------------------------------
/docs/datamapper.md:
--------------------------------------------------------------------------------
1 | # Data Mapper
2 | - - -
3 |
4 | !!! info "NOTE"
5 |
6 | These components have been heavily influenced by [Aura PHP][auraphp] and [Atlas PHP][atlasphp]
7 |
8 | ## Overview
9 |
10 | The Data Mapper pattern as described by [Martin Fowler][datamapper] in [Patterns of Enterprise Application Architecture][eaa] is:
11 |
12 | !!! info "NOTE"
13 |
14 | A layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself.
15 |
16 | The `Phalcon\DataMapper` namespace contains components to help with accessing your data source, with the [Data Mapper][pattern].
17 |
18 | ## PDO
19 |
20 | ### Connection
21 |
22 | One of the components required by this implementation is a PDO connector. The [Phalcon\DataMapper\Pdo\Connection][datamapper-pdo-connection] offers a wrapper to PHP's PDO implementation, making it easier to maintain connections.
23 |
24 | **Connecting to a source**
25 |
26 | ### Connection - Decorated
27 | ### ConnectionLocator
28 |
29 | ### Profiler
30 | ## Query
31 | ### Factory
32 | ### Delete
33 | ### Insert
34 | ### Select
35 | ### Update
36 |
37 | [auraphp]: https://github.com/auraphp
38 | [atlasphp]: https://github.com/atlasphp
39 | [datamapper]: https://martinfowler.com/eaaCatalog/dataMapper.html
40 | [datamapper-pdo-connection]: api/phalcon_datamapper.md#datamapper-pdo-connection
41 | [datamapper-pdo-connection-abstractconnection]: api/phalcon_datamapper.md#datamapper-pdo-connection-abstractconnection
42 | [datamapper-pdo-connection-connectioninterface]: api/phalcon_datamapper.md#datamapper-pdo-connection-connectioninterface
43 | [datamapper-pdo-connection-decorated]: api/phalcon_datamapper.md#datamapper-pdo-connection-decorated
44 | [datamapper-pdo-connection-pdointerface]: api/phalcon_datamapper.md#datamapper-pdo-connection-pdointerface
45 | [datamapper-pdo-connectionlocator]: api/phalcon_datamapper.md#datamapper-pdo-connectionlocator
46 | [datamapper-pdo-connectionlocatorinterface]: api/phalcon_datamapper.md#datamapper-pdo-connectionlocatorinterface
47 | [datamapper-pdo-exception-cannotdisconnect]: api/phalcon_datamapper.md#datamapper-pdo-exception-cannotdisconnect
48 | [datamapper-pdo-exception-connectionnotfound]: api/phalcon_datamapper.md#datamapper-pdo-exception-connectionnotfound
49 | [datamapper-pdo-exception-exception]: api/phalcon_datamapper.md#datamapper-pdo-exception-exception
50 | [datamapper-pdo-profiler-memorylogger]: api/phalcon_datamapper.md#datamapper-pdo-profiler-memorylogger
51 | [datamapper-pdo-profiler-profiler]: api/phalcon_datamapper.md#datamapper-pdo-profiler-profiler
52 | [datamapper-pdo-profiler-profilerinterface]: api/phalcon_datamapper.md#datamapper-pdo-profiler-profilerinterface
53 | [datamapper-query-abstractconditions]: api/phalcon_datamapper.md#datamapper-query-abstractconditions
54 | [datamapper-query-abstractquery]: api/phalcon_datamapper.md#datamapper-query-abstractquery
55 | [datamapper-query-bind]: api/phalcon_datamapper.md#datamapper-query-bind
56 | [datamapper-query-delete]: api/phalcon_datamapper.md#datamapper-query-delete
57 | [datamapper-query-insert]: api/phalcon_datamapper.md#datamapper-query-insert
58 | [datamapper-query-queryfactory]: api/phalcon_datamapper.md#datamapper-query-queryfactory
59 | [datamapper-query-select]: api/phalcon_datamapper.md#datamapper-query-select
60 | [datamapper-query-update]: api/phalcon_datamapper.md#datamapper-query-update
61 | [eaa]: https://martinfowler.com/books/eaa.html
62 |
--------------------------------------------------------------------------------
/docs/namespaces.md:
--------------------------------------------------------------------------------
1 | # Namespaces
2 | - - -
3 |
4 | ## Overview
5 | [Namespaces][namespaces] can be used to avoid class name collisions. This means that if you have two controllers in an application with the same name, a namespace can be used help PHP understand that they are two different classes. Namespaces are also useful when creating bundles or modules.
6 |
7 | ## Activation
8 | If you decided to use namespaces for your application, you will need to instruct your autoloader on where your namespaces reside. This is the most common way to distinguish between namespaces in your application. If you chose to use the [Phalcon\Autoload\Loader][autoload] component, then you will need to register your namespaces accordingly:
9 |
10 | ```php
11 | registerNamespaces(
14 | [
15 | 'MyApp\Admin\Controllers' => '/app/web/admin/controllers/',
16 | 'MyApp\Admin\Models' => '/app/web/admin/models/',
17 | ]
18 | );
19 | ```
20 |
21 | You can also specify the namespace when defining your routes, using the [Router][routing] component:
22 |
23 | ```php
24 | add(
27 | '/admin/invoices/list',
28 | [
29 | 'namespace' => 'MyApp\Admin',
30 | 'controller' => 'Invoices',
31 | 'action' => 'list',
32 | ]
33 | );
34 | ```
35 |
36 | or passing it as part of the route as a parameter
37 |
38 | ```php
39 | add(
42 | '/:namespace/invoices/list',
43 | [
44 | 'namespace' => 1,
45 | 'controller' => 'Invoices',
46 | 'action' => 'list',
47 | ]
48 | );
49 | ```
50 |
51 | Finally, if you are only working with the same namespace for every controller, you can define a default namespace in your [Dispatcher][dispatcher]. Doing so, you will not need to specify the full class in the router path:
52 |
53 | ```php
54 | set(
59 | 'dispatcher',
60 | function () {
61 | $dispatcher = new Dispatcher();
62 |
63 | $dispatcher->setDefaultNamespace(
64 | 'MyApp\Admin\Controllers'
65 | );
66 |
67 | return $dispatcher;
68 | }
69 | );
70 | ```
71 |
72 | ## Controllers
73 | The following example shows how to implement a controller that uses namespaces:
74 |
75 | ```php
76 | hasMany(
126 | 'inv_cst_id',
127 | Customers::class,
128 | 'cst_id',
129 | [
130 | 'alias' => 'customers',
131 | ]
132 | );
133 | }
134 | }
135 | ```
136 |
137 | In PHQL you must write the statements including namespaces:
138 |
139 | ```php
140 |
56 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | ```
96 |
97 | ### Running Psalm
98 |
99 | When you execute `vendor/bin/psalm` in your command-line, you will a get similar output depending on your errors:
100 |
101 | ```bash
102 | Scanning files...
103 | Analyzing files...
104 |
105 | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 60 / 95 (63%)
106 | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
107 | ------------------------------
108 | No errors found!
109 | ------------------------------
110 |
111 | Checks took 0.80 seconds and used 214.993MB of memory
112 | Psalm was able to infer types for 92.9630% of the codebase
113 | ```
114 |
115 | Fix your errors, and re-run Psalm!
116 |
117 | ## Resources
118 | - [Psalm Documentation](https://psalm.dev/docs/)
119 | - [Static Analysis with Psalm PHP](https://www.twilio.com/blog/static-analysis-with-psalm-php)
120 | - [What Is Static Code Analysis?](https://www.perforce.com/blog/sca/what-static-analysis)
121 |
--------------------------------------------------------------------------------
/docs/introduction.md:
--------------------------------------------------------------------------------
1 |
2 | # Phalcon Framework: A PHP framework built as an extension for PHP
3 |
4 | **A full-stack PHP framework delivered as a C-extension**
5 |
6 | [](https://github.com/phalcon/cphalcon/actions/workflows/main.yml)
7 |
8 | ## Mission :rocket:
9 |
10 | Our mission is to empower developers with an advanced, feature-rich tool: Phalcon. This framework is designed to facilitate the development of powerful applications with minimal server resource consumption and optimal performance.
11 |
12 | ## What is Phalcon :question:
13 |
14 | Phalcon is an open-source full-stack framework for PHP, distinguished by its unique architecture written as a C-extension. This means that it is implemented in C and directly integrated into PHP for enhanced performance.
15 |
16 | Its innovative architecture ensures that the framework is always memory-resident, providing functionality on demand without the overhead of file stats and reads typical in traditional PHP frameworks.
17 |
18 | ## Usage :memo:
19 |
20 | Phalcon is designed to be developer-friendly, and you don't need to be familiar with the C language to utilize its power. The framework's interface is exposed as PHP classes under the `Phalcon` namespace, making it accessible and easy to use.
21 |
22 | Phalcon is loosely coupled, allowing developers to use only the objects that they need as glue components based in the needs of their applications.
23 |
24 | !!! info "NOTE"
25 |
26 | The translation of the documentation is driven by enthusiasts and contributors. We invite and appreciate your participation in the translation effort. Contribute new translations or corrections via [GitHub][github_docs] for English or [Crowdin][crowdin] for other languages.
27 |
28 | You can check our [GitHub][github] project for the code and browse through these documents for usage and functionality.
29 |
30 | Since this is a community driven project, you can share your thoughts and requests for functionality you need by issuing a [New Feature Request][new-feature-request] and if you wish vote in GitHub for [existing NFRs][new-feature-request-list].
31 |
32 | Feel free to connect with us using our social media accounts:
33 |
34 |
80 |
81 |
82 | [github]: https://github.com/phalcon/cphalcon
83 | [github_docs]: https://github.com/phalcon/docs
84 | [new-feature-request]: new-feature-request.md
85 | [new-feature-request-list]: new-feature-request-list.md
86 | [discord]: https://phalcon.io/discord
87 | [discussions]: https://phalcon.io/discussions
88 | [github_sponsors]: https://github.com/sponsors/phalcon
89 | [opencollective_sponsors]: https://phalcon.io/fund
90 | [telegram]: https://phalcon.io/telegram
91 | [gab]: https://phalcon.io/gab
92 | [mewe]: https://phalcon.io/mewe
93 | [reddit]: https://phalcon.io/reddit
94 | [fb]: https://phalcon.io/fb
95 | [t]: https://phalcon.io/t
96 |
97 |
98 | - :octicons-video-16:{ .lg .middle } __Videos__
99 |
100 | ---
101 |
102 | [:octicons-chevron-right-12: BitChute](https://phalcon.io/bitchute)
103 |
104 | [:octicons-chevron-right-12: LBRY](https://phalcon.io/lbry)
105 |
106 | [:octicons-chevron-right-12: YouTube](https://phalcon.io/youtube)
107 |
--------------------------------------------------------------------------------
/docs/i18n.md:
--------------------------------------------------------------------------------
1 | # Internationalization
2 | - - -
3 |
4 | ## Overview
5 | Phalcon is written in C as an extension for PHP. There is a [PECL][intl] extension that offers internationalization functions to PHP applications called [intl][intl]. Its documentation can be found in the pages of the official [PHP manual][intl-manual].
6 |
7 | Phalcon does not offer this functionality, since creating such a component would be replicating existing code.
8 |
9 | In the examples below, we will show you how to implement the [intl][intl] extension's functionality into Phalcon powered applications.
10 |
11 | !!! warning "NOTE"
12 |
13 | This guide is not intended to be a complete documentation of the [intl][intl] extension. Please visit the [documentation][intl-book] of the extension for a reference.
14 |
15 | ## Find out Best Available Locale
16 | There are several ways to find out the best available locale using [intl][intl]. One of them is to check the HTTP `Accept-Language` header:
17 |
18 | ```php
19 | format([4560]);
53 |
54 | // USD$ 4,560.5
55 | $formatter = new MessageFormatter('en_US', 'USD$ {0, number}');
56 | echo $formatter->format([4560.50]);
57 |
58 | // ARS$ 1.250,25
59 | $formatter = new MessageFormatter('es_AR', 'ARS$ {0, number}');
60 | echo $formatter->format([1250.25]);
61 | ```
62 |
63 | Message formatting using time and date patterns:
64 |
65 | ```php
66 | format($values);
77 |
78 | // 'À 15:53:01 le 19 avr. 2015, il y avait une perturbation sur la planète 7.'
79 | $pattern = 'À {1, time} le {1, date}, il y avait une perturbation sur la planète {0, number}.';
80 | $formatter = new MessageFormatter('fr_FR', $pattern);
81 | echo $formatter->format($values);
82 | ```
83 |
84 | ## Locale-Sensitive Comparison
85 | The [Collator][collator] class provides string comparison capability with support for appropriate locale-sensitive sort orderings. Check the examples below on the usage of this class:
86 |
87 | ```php
88 | setStrength(Collator::PRIMARY);
97 |
98 | var_dump(
99 | $collator->compare('una canción', 'una cancion')
100 | );
101 |
102 | // Returns that the strings are not equal
103 | $collator->setStrength(Collator::DEFAULT_VALUE);
104 |
105 | var_dump(
106 | $collator->compare('una canción', 'una cancion')
107 | );
108 | ```
109 |
110 | ## Transliteration
111 | [Transliterator][transliterator] provides transliteration of strings:
112 |
113 | ```php
114 | transliterate($string); // garconetudiantoulecole
123 | ```
124 |
125 | [intl]: https://pecl.php.net/package/intl
126 | [intl-manual]: https://www.php.net/manual/en/intro.intl.php
127 | [intl-book]: https://www.php.net/manual/en/book.intl.php
128 | [messageformatter]: https://www.php.net/manual/en/class.messageformatter.php
129 | [collator]: https://www.php.net/manual/en/class.collator.php
130 | [transliterator]: https://www.php.net/manual/en/class.transliterator.php
131 |
--------------------------------------------------------------------------------
/docs/coding-standard.md:
--------------------------------------------------------------------------------
1 | # Phalcon Coding Standard
2 | - - -
3 |
4 | Last update: 2019-07-04
5 |
6 | Phalcon is written in [Zephir][zephir], a language that the Phalcon Team invented and is actively developing. Therefore, there are no established coding standards that developers can follow, should they wish to.
7 |
8 | In this document we outline the coding standard that Phalcon is using for editing Zephir files. The coding standard is a variant of [PSR-12][psr-12] developed by [PHP-FIG][php-fig]
9 |
10 | ## Files
11 | * Files must use only UTF-8 without BOM.
12 | - File names must be named StudlyCaps.
13 | - All files must use the Unix LF (linefeed) line ending.
14 | - All files must end with a single blank line.
15 | - Folders are also named StudlyCaps and the folder/sub-folder tree follows the namespace of the class.
16 |
17 | ```php
18 | phalcon/Acl/Adapter/Memory.zep
19 | ```
20 |
21 | ```php
22 | namespace Phalcon\Acl\Adapter;
23 |
24 | use Phalcon\Acl\Adapter;
25 |
26 | class Memory extends Adapter
27 | {
28 |
29 | }
30 | ```
31 |
32 | - Code must use 4 spaces for indenting, not tabs.
33 | - Lines should be 80 characters or fewer. The hard limit on line length is 120 characters.
34 | - There must be one blank line after the namespace declaration, and there must be one blank line after the block of use declarations.
35 | - There must not be trailing whitespace at the end of non-blank lines.
36 | - Blank lines may be added to improve readability and to indicate related blocks of code.
37 | - There must not be more than one statement per line.
38 |
39 | ## Classes
40 | - Class names must be declared in StudlyCaps.
41 | - Opening braces for classes must go on the next line, and closing braces must go on the next line after the body.
42 | - Abstract classes must be prefixed by `Abstract`
43 | - Interfaces must be suffixed by `Interface`
44 |
45 | ### Constants
46 | - Class constants must be declared in all upper case with underscore separators.
47 | - Class constants must appear at the top of the class.
48 | - Class constants must be sorted alphabetically by constant name.
49 |
50 | ```php
51 | namespace Phalcon\Acl;
52 |
53 | class Enum
54 | {
55 | const ALLOW = 1;
56 | const DENY = 0;
57 | }
58 | ```
59 |
60 | ### Properties
61 | - Class properties must be declared in camelCase.
62 | - Class properties must be sorted alphabetically based on name.
63 | - Whenever possible, properties must have a default value.
64 | - Whenever possible, properties must have a docblock that defines their type with the `@var` declaration.
65 | - Properties must not be prefixed with underscore `_`. The only exception is if the property name is a reserved keyword such as `default`, `namespace` etc.
66 |
67 | ```php
68 | namespace Phalcon\Acl\Adapter;
69 |
70 | use Phalcon\Acl\Adapter;
71 |
72 | class Memory extends Adapter
73 | {
74 | /**
75 | * @var string | null
76 | */
77 | protected activeKey = "" { get };
78 | }
79 | ```
80 |
81 | ### Methods
82 | - Method names must be declared in camelCase.
83 | - Methods must be sorted alphabetically and based on their visibility. The order is `public`, `protected` and `private`. `__construct` if defined must be at the top of the class.
84 | - Method names must not be prefixed with underscore `_`.
85 | - All methods must have a return type. If the method does not return anything it should be marked `void`
86 | - Opening braces for methods must go on the next line, and closing braces must go on the next line after the body.
87 | - Visibility must be declared on all properties and methods; `abstract` and `final` must be declared before the visibility; `static` must be declared after the visibility.
88 |
89 | ```php
90 | abstract public function getElement() -> var;
91 |
92 | final public function getElement() -> var;
93 |
94 | public static function getElement() -> var;
95 | ```
96 |
97 | - Control structure keywords must have one space after them; method and function calls must not.
98 | - Opening braces for control structures must go on the same line, and closing braces must go on the next line after the body.
99 | - Control structures such as `if` must not have parentheses around the conditional, unless it is a complex one.
100 |
101 | ```php
102 | if typeof variable === "array" {
103 |
104 | }
105 | ```
106 |
107 | ### Method Arguments
108 | - In the argument list, there must not be a space before each comma, and there must be one space after each comma.
109 | - Each method must have its type declared before it
110 | - Method arguments with default values must go at the end of the argument list.
111 |
112 | ```php
113 | public function setElement(string! name, var value) -> void;
114 | ```
115 |
116 | - Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list must be on the next line, and there must be only one argument per line.
117 |
118 | ### PHP Files
119 | PHP files such as tests must follow [PSR-12][psr-12].
120 |
121 |
122 | [php-fig]: https://www.php-fig.org/
123 | [psr-12]: https://www.php-fig.org/psr/psr-12/
124 | [zephir]: https://zephir-lang.com
125 |
--------------------------------------------------------------------------------
/docs/domain.md:
--------------------------------------------------------------------------------
1 | # Domain
2 | - - -
3 |
4 | !!! warning "NOTE"
5 |
6 | In future versions of Phalcon, this component will be reworked to follow the [Payload Interop][payload-interop] interface.
7 |
8 | The domain component incorporates components that are used for the implementation of the [Action Domain Responder][adr] ([ADR][adr-jones]) pattern and can also be used when implementing [Domain Driven Design][ddd].
9 |
10 | ## Payload
11 | The [Action Domain Responder][adr] requires a data transfer mechanism between the three layers to serve your application. The [Phalcon\Domain\Payload][payload-payload] is a data transfer object that is used to send data between the three layers of the pattern.
12 |
13 | ```php
14 | newInstance();
48 | ?>
49 | ```
50 |
51 | ## Interfaces
52 | There are three interfaces that you can take advantage of if you wish to extend the object.
53 |
54 | | Interface | Description |
55 | |---------------------|--------------------------------------|
56 | | `ReadableInterface` | contains only read methods |
57 | | `WritableInterface` | contains only write methods |
58 | | `PayloadInterface` | contains both read and write methods |
59 |
60 | ## Status Values
61 | The [Phalcon\Domain\Payload\Status][payload-status] class contains several constants to help with the domain status of your Payload objects. You can always extend the class and introduce your own domain statuses, depending on the needs of your application.
62 |
63 | * `ACCEPTED`
64 | * `AUTHENTICATED`
65 | * `AUTHORIZED`
66 | * `CREATED`
67 | * `DELETED`
68 | * `ERROR`
69 | * `FAILURE`
70 | * `FOUND`
71 | * `NOT_ACCEPTED`
72 | * `NOT_AUTHENTICATED`
73 | * `NOT_AUTHORIZED`
74 | * `NOT_CREATED`
75 | * `NOT_DELETED`
76 | * `NOT_FOUND`
77 | * `NOT_UPDATED`
78 | * `NOT_VALID`
79 | * `PROCESSING`
80 | * `SUCCESS`
81 | * `UPDATED`
82 | * `VALID`
83 |
84 | These statuses can be used at the display/view layer of your application to process domain objects retrieved via `Payload::getOutput()`.
85 |
86 | ## Example
87 | ```php
88 | newInstance();
101 |
102 | $report = Reports::find(
103 | [
104 | 'conditions' => 'reportId = :reportId:',
105 | 'bind' => [
106 | 'reportId' => $reportId,
107 | ],
108 | ]
109 | );
110 |
111 | if (false === $report) {
112 | $payload
113 | ->setStatus(Status::NOT_FOUND)
114 | ->setInput(func_get_args())
115 | ;
116 | } else {
117 | $payload
118 | ->setStatus(Status::FOUND)
119 | ->setOutput($report)
120 | ;
121 | }
122 |
123 | return $payload;
124 | }
125 | }
126 | ```
127 |
128 | ## Links
129 |
130 | * [Action Domain Responder][adr]
131 | * [Clarifications to a review of Action Domain Responder][adr-clarifications]
132 | * [Payload Interop][payload-interop]
133 |
134 |
135 | [adr]: https://en.wikipedia.org/wiki/Action%E2%80%93domain%E2%80%93responder
136 | [adr-jones]: https://pmjones.io/adr/
137 | [adr-clarifications]: https://paul-m-jones.com/post/2018/12/19/clarifications-to-a-review-of-action-domain-responder/
138 | [ddd]: https://en.wikipedia.org/wiki/Domain-driven_design
139 | [payload-interop]: https://github.com/payload-interop/payload-interop
140 | [payload-payload]: api/phalcon_domain.md#domain-payload-payload
141 | [payload-payloadfactory]: api/phalcon_domain.md#domain-payload-payloadfactory
142 | [payload-payloadinterface]: api/phalcon_domain.md#domain-payload-payloadinterface
143 | [payload-readableinterface]: api/phalcon_domain.md#domain-payload-readableinterface
144 | [payload-status]: api/phalcon_domain.md#domain-payload-status
145 | [payload-writeableinterface]: api/phalcon_domain.md#domain-payload-writeableinterface
146 |
--------------------------------------------------------------------------------
/docs/api/phalcon_autoload.md:
--------------------------------------------------------------------------------
1 |
2 | * [Phalcon\Autoload\Exception](#autoload-exception)
3 | * [Phalcon\Autoload\Loader](#autoload-loader)
4 |
5 |
Class Phalcon\Autoload\Exception
6 |
7 | [Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/Autoload/Exception.zep)
8 |
9 | | Namespace | Phalcon\Autoload |
10 | | Extends | \Exception |
11 |
12 | Exceptions thrown in Phalcon\Autoload will use this class
13 |
14 |
15 |
16 |
Class Phalcon\Autoload\Loader
17 |
18 | [Source on GitHub](https://github.com/phalcon/cphalcon/blob/{{ pageVersion }}.x/phalcon/Autoload/Loader.zep)
19 |
20 | | Namespace | Phalcon\Autoload |
21 | | Uses | Phalcon\Events\AbstractEventsAware |
22 | | Extends | AbstractEventsAware |
23 |
24 | The Phalcon Autoloader provides an easy way to automatically load classes
25 | (namespaced or not) as well as files. It also features extension loading,
26 | allowing the user to autoload files with different extensions than .php.
27 |
28 |
29 | ## Properties
30 | ```php
31 | /**
32 | * @var string|null
33 | */
34 | protected checkedPath;
35 |
36 | /**
37 | * @var array
38 | */
39 | protected classes;
40 |
41 | /**
42 | * @var array
43 | */
44 | protected debug;
45 |
46 | /**
47 | * @var array
48 | */
49 | protected directories;
50 |
51 | /**
52 | * @var array
53 | */
54 | protected extensions;
55 |
56 | /**
57 | * @var string|callable
58 | */
59 | protected fileCheckingCallback = is_file;
60 |
61 | /**
62 | * @var array
63 | */
64 | protected files;
65 |
66 | /**
67 | * @var string|null
68 | */
69 | protected foundPath;
70 |
71 | /**
72 | * @var bool
73 | */
74 | protected isDebug = false;
75 |
76 | /**
77 | * @var bool
78 | */
79 | protected isRegistered = false;
80 |
81 | /**
82 | * @var array
83 | */
84 | protected namespaces;
85 |
86 | ```
87 |
88 | ## Methods
89 |
90 | ```php
91 | public function __construct( bool $isDebug = bool );
92 | ```
93 | Loader constructor.
94 |
95 |
96 | ```php
97 | public function addClass( string $name, string $file ): Loader;
98 | ```
99 | Adds a class to the internal collection for the mapping
100 |
101 |
102 | ```php
103 | public function addDirectory( string $directory ): Loader;
104 | ```
105 | Adds a directory for the loaded files
106 |
107 |
108 | ```php
109 | public function addExtension( string $extension ): Loader;
110 | ```
111 | Adds an extension for the loaded files
112 |
113 |
114 | ```php
115 | public function addFile( string $file ): Loader;
116 | ```
117 | Adds a file to be added to the loader
118 |
119 |
120 | ```php
121 | public function addNamespace( string $name, mixed $directories, bool $prepend = bool ): Loader;
122 | ```
123 |
124 |
125 |
126 | ```php
127 | public function autoload( string $className ): bool;
128 | ```
129 | Autoloads the registered classes
130 |
131 |
132 | ```php
133 | public function getCheckedPath(): string | null;
134 | ```
135 | Get the path the loader is checking for a path
136 |
137 |
138 | ```php
139 | public function getClasses(): array;
140 | ```
141 | Returns the class-map currently registered in the autoloader
142 |
143 |
144 | ```php
145 | public function getDebug(): array;
146 | ```
147 | Returns debug information collected
148 |
149 |
150 | ```php
151 | public function getDirectories(): array;
152 | ```
153 | Returns the directories currently registered in the autoloader
154 |
155 |
156 | ```php
157 | public function getExtensions(): array;
158 | ```
159 | Returns the file extensions registered in the loader
160 |
161 |
162 | ```php
163 | public function getFiles(): array;
164 | ```
165 | Returns the files currently registered in the autoloader
166 |
167 |
168 | ```php
169 | public function getFoundPath(): string | null;
170 | ```
171 | Get the path when a class was found
172 |
173 |
174 | ```php
175 | public function getNamespaces(): array;
176 | ```
177 | Returns the namespaces currently registered in the autoloader
178 |
179 |
180 | ```php
181 | public function isRegistered(): bool;
182 | ```
183 | returns isRegister
184 |
185 |
186 | ```php
187 | public function loadFiles(): void;
188 | ```
189 | Checks if a file exists and then adds the file by doing virtual require
190 |
191 |
192 | ```php
193 | public function register( bool $prepend = bool ): Loader;
194 | ```
195 | Register the autoload method
196 |
197 |
198 | ```php
199 | public function setClasses( array $classes, bool $merge = bool ): Loader;
200 | ```
201 | Register classes and their locations
202 |
203 |
204 | ```php
205 | public function setDirectories( array $directories, bool $merge = bool ): Loader;
206 | ```
207 | Register directories in which "not found" classes could be found
208 |
209 |
210 | ```php
211 | public function setExtensions( array $extensions, bool $merge = bool ): Loader;
212 | ```
213 | Sets an array of file extensions that the loader must try in each attempt
214 | to locate the file
215 |
216 |
217 | ```php
218 | public function setFileCheckingCallback( mixed $method = null ): Loader;
219 | ```
220 | Sets the file check callback.
221 |
222 | ```php
223 | // Default behavior.
224 | $loader->setFileCheckingCallback("is_file");
225 |
226 | // Faster than `is_file()`, but implies some issues if
227 | // the file is removed from the filesystem.
228 | $loader->setFileCheckingCallback("stream_resolve_include_path");
229 |
230 | // Do not check file existence.
231 | $loader->setFileCheckingCallback(null);
232 | ```
233 |
234 |
235 | ```php
236 | public function setFiles( array $files, bool $merge = bool ): Loader;
237 | ```
238 | Registers files that are "non-classes" hence need a "require". This is
239 | very useful for including files that only have functions
240 |
241 |
242 | ```php
243 | public function setNamespaces( array $namespaces, bool $merge = bool ): Loader;
244 | ```
245 | Register namespaces and their related directories
246 |
247 |
248 | ```php
249 | public function unregister(): Loader;
250 | ```
251 | Unregister the autoload method
252 |
253 |
254 | ```php
255 | protected function requireFile( string $file ): bool;
256 | ```
257 | If the file exists, require it and return true; false otherwise
258 |
--------------------------------------------------------------------------------
/docs/unit-testing.md:
--------------------------------------------------------------------------------
1 | # Unit Testing
2 | - - -
3 |
4 | ## Overview
5 |
6 | Writing proper tests can assist in writing better software. If you set up proper test cases you can eliminate most functional bugs and better maintain your software.
7 |
8 | ## Integrating PHPUnit with Phalcon
9 |
10 | ```bash
11 | composer require --dev phpunit/phpunit:^9.0
12 | ```
13 |
14 | or by manually adding it to `composer.json`:
15 |
16 | ```json
17 | {
18 | "require-dev": {
19 | "phpunit/phpunit": "^9.0"
20 | }
21 | }
22 | ```
23 |
24 | Once PHPUnit is installed, create a directory called `tests` in project root directory with a subdirectory called `Unit`:
25 |
26 | ```
27 | app/
28 | src/
29 | public/
30 | tests/Unit/
31 | ```
32 |
33 | ### Configure Test Namespace
34 |
35 | In order to autoload our test directory, we must add our test namespace to composer. Add the below to composer and modify it to fit your needs.
36 |
37 | ```json
38 | {
39 | "autoload-dev": {
40 | "psr-4": {
41 | "Tests\\": "tests"
42 | }
43 | }
44 | }
45 | ```
46 |
47 | Now, create a `phpunit.xml` file as follows:
48 |
49 | ### The `phpunit.xml` file
50 |
51 | Modify the `phpunit.xml` below to fit your needs and save it in your project root directory. This will run any tests under the `tests/Unit` directory.
52 |
53 | ```xml
54 |
55 |
56 |
65 |
66 |
67 | ./tests/Unit
68 |
69 |
70 | ```
71 |
72 | ### Phalcon Incubator Test
73 |
74 | Phalcon provides a test library that provides few abstract classes you can use to bootstrap the Unit Tests themselves. These files exist in [Phalcon Incubator Test](https://github.com/phalcon/incubator-test) repository.
75 |
76 | You can use the Incubator test library by adding it as a dependency:
77 |
78 | ```bash
79 | composer require --dev phalcon/incubator-test:^v1.0.0-alpha.1
80 | ```
81 |
82 | or by manually adding it to `composer.json`:
83 |
84 | ```json
85 | {
86 | "require-dev": {
87 | "phalcon/incubator-test": "^v1.0.0-alpha.1"
88 | }
89 | }
90 | ```
91 |
92 | ## Creating a Unit Test
93 |
94 | It is always wise to autoload your classes using namespaces. The configuration below assumes that you are using PSR-4 to autoload your project classes via a composer configuration. Doing so, the autoloader will make sure the proper files are loaded so all you need to do is create the files and phpunit will run the tests for you.
95 |
96 | This example does not contain a config file, as most cases you should be mocking your dependencies. If you happen to need one, you can add to the `DI` in the `AbstractUnitTest`.
97 |
98 | ### Abstract Unit Test
99 | First create a base Unit Test called `AbstractUnitTest.php` in your `tests/Unit` directory:
100 |
101 | ```php
102 | loaded = true;
127 | }
128 |
129 | public function __destruct()
130 | {
131 | if (!$this->loaded) {
132 | throw new IncompleteTestError(
133 | "Please run parent::setUp()."
134 | );
135 | }
136 | }
137 | }
138 | ```
139 |
140 | ### Your First Test
141 |
142 | Create the test below and save it in your `tests/Unit` directory.
143 |
144 | ```php
145 | assertEquals(
156 | "roman",
157 | "roman",
158 | "This will pass"
159 | );
160 |
161 | $this->assertEquals(
162 | "hope",
163 | "ava",
164 | "This will fail"
165 | );
166 | }
167 | }
168 | ```
169 |
170 | If you need to overload the `setUp` method, it is important you call the parent or Phalcon will not properly initialize.
171 |
172 | ```php
173 | protected function setUp(): void
174 | {
175 | parent::setUp();
176 |
177 | //...
178 | }
179 | ````
180 |
181 | ### Running Unit Tests
182 |
183 | When you execute `vendor/bin/phpunit` in your command-line, you will get the following output:
184 |
185 | ```bash
186 | $ phpunit
187 | PHPUnit 9.5.23 by Sebastian Bergmann and contributors.
188 |
189 | Runtime: PHP 8.1.8 with Xdebug 3.1.5
190 | Configuration: /var/www//phpunit.xml
191 |
192 | Time: 3 ms, Memory: 3.25Mb
193 |
194 | There was 1 failure:
195 |
196 | 1) Test\Unit\UnitTest::testTestCase
197 | This will fail
198 | Failed asserting that two strings are equal.
199 | --- Expected
200 | +++ Actual
201 | @@ @@
202 | -'hope'
203 | +'ava'
204 |
205 | /var/www/tests/Unit/UnitTest.php:25
206 |
207 | FAILURES!
208 | Tests: 1, Assertions: 2, Failures: 1.
209 | ```
210 |
211 | ## Resources
212 | - [PHPUnit Documentation](https://phpunit.de/documentation.html)
213 | - [Getting Started with TDD in PHP](https://www.sitepoint.com/re-introducing-phpunit-getting-started-tdd-php/)
214 | - [Writing Great Unit Tests](https://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/)
215 | - [What Is Mocking In PHP Unit Testing](https://www.clariontech.com/blog/what-is-mocking-in-php-unit-testing)
216 |
--------------------------------------------------------------------------------
/docs/html-link.md:
--------------------------------------------------------------------------------
1 | # HTML Link
2 | - - -
3 |
4 | ## Overview
5 | [Phalcon\Html\Link\EvolvableLink][html-link-evolvablelink], [Phalcon\Html\Link\EvolvableLinkProvider][html-link-evolvablelinkprovider], [Phalcon\Html\Link\Link][html-link-link] and [Phalcon\Html\Link\LinkProvider][html-link-linkprovider] are classes that implement the interfaces based on [PSR-13][psr-13], but with much stricter types
6 |
7 | !!! info "NOTE"
8 |
9 | This component does not generate any HTML links. It just stores the links. You will need to create your own serializers that will parse these objects and generate the necessary output. The [Phalcon\Html\Link\Serializer\Header][html-link-serializer-header] serializer is available for you to use.
10 |
11 | ### Operations
12 | The `Phalcon\Html\Link\*` components implement methods that are inline with [PSR-13][psr-13], but do not implement the particular interface. A package that implements [PSR-13][psr-13] is available, that uses the `Phalcon\Html\Link\*` components. The package is located [here][proxy-psr13]. To use it, you will need to have Phalcon installed and then using composer you can install the proxy package.
13 |
14 | ```sh
15 | composer require phalcon/proxy-psr13
16 | ```
17 |
18 | Using the proxy classes allows you to follow [PSR-13][psr-13] and use it with any other package that needs that interface.
19 |
20 | ## Link
21 | The [Phalcon\Html\Link\Link][html-link-link] is used to create a link and assign attributes to it upon construction.
22 |
23 | ```php
24 | true,
31 | 'two' => 123,
32 | 'three' => 'four',
33 | 'five' => [
34 | 'six',
35 | 'seven',
36 | ],
37 | ];
38 |
39 | $link = new Link('payment', $href, $attributes);
40 | ```
41 |
42 | ## LinkProvider
43 | The [Phalcon\Html\Link\LinkProvider][html-link-linkprovider] is used as a container of [Phalcon\Html\Link\Link][html-link-link] objects. You can add them in the provider and then access them as a whole or retrieve them by `rel`.
44 |
45 | ```php
46 | getLinksByRel('cite-as')
60 | );
61 |
62 | // [
63 | // Link('cite-as', 'https://test.phalcon.ld'),
64 | // ]
65 | ```
66 |
67 | ## EvolvableLink
68 | Link objects are immutable. However, there is a need to manipulate them based on your application needs. The [Phalcon\Html\Link\EvolvableLink][html-link-evolvablelink] is available, allowing you to manipulate the link.
69 |
70 | ```php
71 | true];
77 |
78 | $link = new EvolvableLink('payment', $href, $attributes);
79 |
80 | $newInstance = $link->withAttribute('two', 'three');
81 |
82 | var_dump(
83 | $newInstance->getAttributes()
84 | );
85 |
86 | // [
87 | // 'one' => true,
88 | // 'two' => 'three',
89 | // ];
90 | ```
91 |
92 | ## EvolvableLinkProvider
93 | The [Phalcon\Html\Link\LinkProvider][html-link-linkprovider] is used as a container of [Phalcon\Html\Link\EvolvableLink][html-link-evolvablelink] objects. You can add them in the provider and then access them as a whole or retrieve them by `rel`.
94 |
95 | ```php
96 | getLinksByRel('cite-as')
110 | );
111 |
112 | // [
113 | // Link('cite-as', 'https://test.phalcon.ld'),
114 | // ]
115 | ```
116 |
117 | ## Serializers
118 | ### Header
119 | You can use a serializer to parse the `Phalcon\Html\Link\*` objects and create the necessary headers. Phalcon comes with the [Phalcon\Html\Link\Serializer\Header][html-link-serializer-header] serializer, to help with the task of serializing links for the headers:
120 |
121 | ```php
122 | serialize([$link]);
132 | // ; rel="prefetch"';
133 |
134 |
135 | $links = [
136 | (new EvolvableLink('preload', '/1'))
137 | ->withAttribute('as', 'image')
138 | ->withAttribute('nopush', true),
139 | (new EvolvableLink('alternate', '/2'))
140 | ->withRel('next')
141 | ->withAttribute('hreflang', ['en', 'es'])
142 | ];
143 |
144 | echo $serializer->serialize([$link]);
145 | // 1>; rel="preload"; as="image"; nopush,
146 | // 2>; rel="alternate next"; hreflang="en"; hreflang="es"
147 | ;
148 | ```
149 |
150 | ### Custom
151 | You can create your own serializers for relevant links by extending the [Phalcon\Html\Link\Serializer\SerializerInterface][html-link-serializer-serializerinterface]
152 |
153 | ```php
154 | '/tmp',
28 | ]
29 | );
30 |
31 | $session->setHandler($adapter);
32 |
33 | $session->start();
34 |
35 | return $session;
36 | };
37 |
38 | $container['cookies'] = function() {
39 | $cookies = new Cookies();
40 |
41 | $cookies->useEncryption(false);
42 |
43 | return $cookies;
44 | };
45 |
46 | class SomeClass extends Injectable
47 | {
48 | public function someMethod()
49 | {
50 | $cookies = $this->getDI()->getCookies();
51 |
52 | $cookies->set(
53 | 'mycookie',
54 | 'test',
55 | time() + 3600,
56 | '/'
57 | );
58 | }
59 | }
60 |
61 | $class = new MyClass();
62 |
63 | $class->setDI($container);
64 |
65 | $class->someMethod();
66 |
67 | $container['cookies']->send();
68 |
69 | var_dump($_SESSION);
70 | var_dump($_COOKIE);
71 | ```
72 |
73 | ### Database
74 |
75 | !!! info "NOTE"
76 |
77 | Remember to include the register information for your `db` service, i.e. adapter, connection parameters etc.
78 |
79 | ```php
80 | setShared(
88 | 'db',
89 | function () {
90 | return new Mysql(
91 | [
92 | 'host' => '127.0.0.1',
93 | 'username' => 'root',
94 | 'password' => '',
95 | 'dbname' => 'test',
96 | 'charset' => 'utf8',
97 | ]
98 | );
99 | }
100 | );
101 |
102 | $result = $container['db']->query('SELECT * FROM customers');
103 | ```
104 |
105 | ### Single/Multi-Module Applications
106 |
107 | !!! info "NOTE"
108 |
109 | Remember to add to the script how you are creating the `Phalcon\Mvc\Application` instance and how you register your modules
110 |
111 | ```php
112 | setDI($container);
124 |
125 | // register modules if any
126 |
127 | $response = $application->handle(
128 | $_SERVER["REQUEST_URI"]
129 | );
130 |
131 | echo $response->getContent();
132 | ```
133 |
134 | Include models and controllers as part of the test:
135 |
136 | ```php
137 | setDI($container);
151 |
152 | class IndexController extends Controller
153 | {
154 | public function indexAction() {
155 | /* your content here */
156 | }
157 | }
158 |
159 | class Users extends Model
160 | {
161 | }
162 |
163 | $response = $application->handle(
164 | $_SERVER["REQUEST_URI"]
165 | );
166 |
167 | echo $response->getContent();
168 | ```
169 |
170 | ### Micro Application
171 | For micro applications, you can use the skeleton script below:
172 |
173 | ```php
174 | handle(
188 | $_SERVER["REQUEST_URI"]
189 | );
190 | ```
191 |
192 | ### ORM
193 |
194 | !!! info "NOTE"
195 |
196 | You can provide your own database schema or even better, use any of the existing schemas in our testing suite (located in `tests/_data/assets/db/schemas/` in the repository).
197 |
198 | ```php
199 | 'localhost',
213 | 'username' => 'root',
214 | 'password' => '',
215 | 'dbname' => 'test',
216 | ]
217 | );
218 |
219 | $connection->setEventsManager($eventsManager);
220 |
221 | $eventsManager->attach(
222 | 'db:beforeQuery',
223 | function ($event, $connection) {
224 | echo $connection->getSqlStatement(), ' ' . PHP_EOL;
225 | }
226 | );
227 |
228 | $container['db'] = $connection;
229 | $container['modelsManager'] = new ModelsManager();
230 | $container['modelsMetadata'] = new ModelsMetadata();
231 |
232 | if (true !== $connection->tableExists('user', 'test')) {
233 | $connection->execute(
234 | 'CREATE TABLE user (
235 | id integer primary key auto_increment,
236 | email varchar(120) not null
237 | )'
238 | );
239 | }
240 |
241 | class User extends Model
242 | {
243 | public $id;
244 |
245 | public $email;
246 |
247 | public static function createNewUserReturnId()
248 | {
249 | $newUser = new User();
250 |
251 | $newUser->email = 'test';
252 |
253 | if (false === $newUser->save()) {
254 | return false;
255 | }
256 |
257 | return $newUser->id;
258 | }
259 | }
260 |
261 | echo User::createNewUserReturnId();
262 | ```
263 |
264 | [issues]: https://github.com/phalcon/cphalcon/issues
265 | [gist]: https://gist.github.com/
266 |
--------------------------------------------------------------------------------
/docs/contributions.md:
--------------------------------------------------------------------------------
1 | # Contributions
2 | - - -
3 |
4 | # Contributing to Phalcon
5 | Phalcon is an open source project and relies heavily on volunteer efforts and contributions. We welcome contributions from everyone!
6 |
7 | Please take a few moments to review this document to understand the contribution process and make it as efficient as possible for all. By following these guidelines, we can have faster resolution of issues, better communication, and we can all move the project forward!
8 |
9 | The Phalcon source code (along with documentation, websites etc.) is stored in [GitHub][github]. You can browse our repositories in our [organization page][phalcon-org].
10 |
11 | If you wish to contribute to Phalcon, you can do so by issuing a [GitHub pull request][github-pr].
12 |
13 | When you create a pull request, we have a handy template to help you describe what is the scope of the pull request. It is very important and helpful to the community that you add tests to your pull request. Each pull request will be reviewed by a core contributor (someone with permissions to merge pull requests). Based on the type and content of the pull request, it could be:
14 |
15 | * merged immediately or
16 | * put on hold, where the reviewer requires changes (styling, tests etc.)
17 | * put on hold, if discussion is necessary (community, core team etc.)
18 | * rejected
19 |
20 | !!! warning "NOTE"
21 |
22 | If your pull request is a new feature, it is best to discuss with the core team first, to ensure that it will align with the evolution of the framework.
23 |
24 | !!! danger "NOTE"
25 |
26 | Please make sure that the target branch that you send your pull request is correct and that you have already rebased your code. Pull requests to the **master** branch are not allowed
27 |
28 | ## Documentation
29 | If programming in Zephir seems daunting, there are plenty of areas that you can contribute. You can always check the documentation for any typographic or context errors. You could also enhance the documentation with more examples in the respective pages.
30 |
31 | All you have to do is go to our [docs-apps][phalcon-docs-apps] repository, fork it, make the changes and send us a pull request.
32 |
33 | ## Translations
34 | We have removed the translations from v5.5.x onward. There was not that much traffic from the community to help with translating the documentation to different languages.
35 |
36 | ## Questions and Support
37 |
38 | !!! danger "NOTE"
39 |
40 | We only accept bug reports, new feature requests and pull requests in GitHub. For questions regarding the usage of the framework or support requests please visit the [official discussions page][phalcon-discussions] or our [Discord][phalcon-discord] server.
41 |
42 | ## Bug Report Checklist
43 | - Make sure you are using the latest released version of Phalcon before creating an issue in GitHub.
44 | - Only bugs found in the latest released version of Phalcon will be addressed.
45 | - We have a handy template when creating an issue to help you provide as much information for the core team to reproduce and address. Being able to reproduce a bug significantly reduces the time to find the cause and fix it. Scripts of even failing tests are more than appreciated. Please check how to create the [reproducible tests][tests] page for more information.
46 | - As part of your report, please include additional information such as the OS, PHP version, Phalcon version, web server, memory etc.
47 | - If you're submitting a [Segmentation Fault][segfault] error, we require a backtrace. Please check the [Generating a Backtrace](#generating-a-backtrace) section for more information.
48 |
49 | ### Generating a Backtrace
50 | Sometimes due to [Segmentation Fault][segfault] error, Phalcon could crash some of your web server processes. In order to help us find the cause of this segmentation fault, we will need the crash backtrace.
51 |
52 | Please check the following links for instructions on how to generate the backtrace:
53 |
54 | * [Generating a gdb backtrace][gdb]
55 | * [Generating a backtrace, with a compiler, on Win32][gdb-w32]
56 | * [Debugging Symbols][symbols]
57 | * [Building PHP][building-php]
58 |
59 | ## Pull Request Checklist
60 | - Pull requests to the `master` branch are not accepted. Please fork the repository and create your branch from the necessary "source" branch, for instance `4.0.x` and if need be rebase your branch before submitting your pull request. If there are collisions, we will ask you to rebase your branch again.
61 | - Add tests to your pull request or adjust existing ones. This is very important since it helps justify your pull request. Please check our [testing][env] page for more information on how to set up a test environment and how to write tests.
62 | - Since Phalcon is written in [Zephir][zephir], please do not submit commits that modify the C generated files directly
63 | - Phalcon follows a specific coding style. Please install the `editorconfig` plugin in your favorite IDE to take advantage of the supplied `.editorconfig` file that comes with this repository and not to have to worry about coding standards. All tests (PHP code), follow the [PSR-12][psr-12] standard
64 | - Remove any change to `ext/kernel`, `*.zep.c` and `*.zep.h` files before submitting the pull request
65 | - More information [here][pr].
66 |
67 | Before submitting **new functionality**, please open a [NFR][nfr] as a new issue on GitHub to discuss the impact of including the functionality or changes in the core extension. Once the functionality is approved, make sure your PR contains the following:
68 |
69 | - An update to the `CHANGELOG.md`
70 | - Unit Tests
71 | - Documentation or Usage Examples
72 |
73 | ## Getting Support
74 | If you have any questions about how to use Phalcon, please see the [support page][support].
75 |
76 | ## Requesting Features
77 | If you have any changes or new features in mind, please fill an [NFR][nfr].
78 |
79 | Thanks!
80 |
81 |
82 | <3 Phalcon Team
83 |
84 | [github]: https://github.com
85 | [phalcon-org]: https://github.com/phalcon
86 | [github-pr]: https://help.github.com/articles/using-pull-requests/
87 | [phalcon-docs-app]: https://github.com/phalcon/docs-app
88 | [phalcon-discussions]: https://phalcon.io/discussions
89 | [phalcon-discord]: https://phalcon.io/discord
90 | [tests]: reproducible-tests.md
91 | [segfault]: https://en.wikipedia.org/wiki/Segmentation_fault
92 | [gdb]: https://bugs.php.net/bugs-generating-backtrace.php
93 | [gdb-w32]: https://bugs.php.net/bugs-generating-backtrace-win32.php
94 | [symbols]: https://github.com/oerdnj/deb.sury.org/wiki/Debugging-symbols
95 | [building-php]: https://www.phpinternalsbook.com/build_system/building_php.html
96 | [env]: testing-environment.md
97 | [zephir]: https://zephir-lang.com
98 | [psr-12]: https://www.php-fig.org/psr/
99 | [pr]: new-pull-request.md
100 | [nfr]: new-feature-request.md
101 | [support]: https://phalcon.io/support
102 |
--------------------------------------------------------------------------------
/docs/api/phalcon_domain.md:
--------------------------------------------------------------------------------
1 |
2 | * [Phalcon\Domain\Payload\Payload](#domain-payload-payload)
3 | * [Phalcon\Domain\Payload\PayloadFactory](#domain-payload-payloadfactory)
4 | * [Phalcon\Domain\Payload\PayloadInterface](#domain-payload-payloadinterface)
5 | * [Phalcon\Domain\Payload\ReadableInterface](#domain-payload-readableinterface)
6 | * [Phalcon\Domain\Payload\Status](#domain-payload-status)
7 | * [Phalcon\Domain\Payload\WriteableInterface](#domain-payload-writeableinterface)
8 |
9 |