赞
踩
Symfony官网:https://symfony.com/
我迫不及待地想向大家介绍Symfony这个框架以及它的众多组件。原因在序章里进行了简单说明,这里将会详细展开。像Symfony的历史背景、作者等这些无助于日常开发的信息,网上非常多这类介绍信息,本文不再赘述。
当你试图学习Symfony的4.x或5.x版本时,你可能会发现,网上找不到很多中文教程。直接硬啃官网,可能会碍于英语阅读能力,学习起来感觉非常吃力。尽管如此,我仍然非常推荐你通过本文了解这个框架,这个框架构筑起庞大的PHP生态,你值得拥有。令我觉得惊讶的是,它的诸多组件明明用于非常多的框架和三方包,却不为人知,太说不过去了。
现在,先让我们快速看看Symfony框架都用到了哪些包。以下均使用当前最新版Symfony 5.1进行演示。你可以选择跟随文章进行操作,如果你已经比较熟悉相关类似的流程,可以直接阅读你感兴趣的部分。
首先我们要完成这些操作:
# 检查环境配置
symfony check:requirements
# 创建一个传统的完整网站应用
symfony new my_project --full
cd my_project/
symfony server:start
执行命令查看该项目已安装的包
composer info
仔细观察输出的结果
doctrine/dbal 2.11.1 Powerful PHP database abstraction layer (DBAL) with many features for... doctrine/doctrine-bundle 2.1.2 Symfony DoctrineBundle doctrine/doctrine-migrations-bundle 3.0.1 Symfony DoctrineMigrationsBundle doctrine/event-manager 1.1.1 The Doctrine Event Manager is a simple PHP event system that was buil... doctrine/inflector 1.4.3 PHP Doctrine Inflector is a small library that can perform string man... doctrine/instantiator 1.3.1 A small, lightweight utility to instantiate objects in PHP without in... doctrine/lexer 1.2.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recur... doctrine/migrations 3.0.1 PHP Doctrine Migrations project offer additional functionality on top... doctrine/orm v2.7.3 Object-Relational-Mapper for PHP doctrine/persistence 2.0.0 The Doctrine Persistence project is a set of shared interfaces and fu... doctrine/reflection 1.2.1 The Doctrine Reflection project is a simple library used by the vario... doctrine/sql-formatter 1.1.1 a PHP SQL highlighting library symfony/config v5.1.7 Symfony Config Component symfony/console v5.1.7 Symfony Console Component symfony/css-selector v5.1.7 Symfony CssSelector Component symfony/debug-bundle v5.1.7 Symfony DebugBundle symfony/debug-pack v1.0.8 A debug pack for Symfony projects symfony/dependency-injection v5.1.7 Symfony DependencyInjection Component symfony/deprecation-contracts v2.2.0 A generic function and convention to trigger deprecation notices symfony/doctrine-bridge v5.1.7 Symfony Doctrine Bridge symfony/dom-crawler v5.1.7 Symfony DomCrawler Component symfony/dotenv v5.1.7 Registers environment variables from a .env file symfony/error-handler v5.1.7 Symfony ErrorHandler Component symfony/event-dispatcher v5.1.7 Symfony EventDispatcher Component symfony/event-dispatcher-contracts v2.2.0 Generic abstractions related to dispatching event symfony/expression-language v5.1.7 Symfony ExpressionLanguage Component symfony/filesystem v5.1.7 Symfony Filesystem Component symfony/finder v5.1.7 Symfony Finder Component symfony/flex v1.9.6 Composer plugin for Symfony
它包主要由两大厂商提供:“symfony”和“doctrine”。“Doctrine”也是PHP业界内著名的厂商,它提供的ORM库包括MySQL和MongoDB,功能和用法都非常成熟,体验上有JAVA的影子。
另一方面,创建Laravel项目执行同样的操作,得到安装包列表,同样包含大量symfony的包。
symfony/error-handler v5.1.7 Symfony ErrorHandler Component
symfony/event-dispatcher v5.1.7 Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v2.2.0 Generic abstractions related to dispatching eve
symfony/finder v5.1.7 Symfony Finder Component
symfony/http-client-contracts v2.2.0 Generic abstractions related to HTTP clients
symfony/http-foundation v5.1.7 Symfony HttpFoundation Component
symfony/http-kernel v5.1.7 Symfony HttpKernel Component
symfony/mime v5.1.7 A library to manipulate MIME messages
symfony/polyfill-ctype v1.18.1 Symfony polyfill for ctype functions
symfony/polyfill-iconv v1.18.1 Symfony polyfill for the Iconv exten
最后我们再来看看ThinkPHP 6框架的安装包列表,真是神奇,居然也有Symfony的包。
symfony/polyfill-mbstring v1.18.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72 v1.18.1 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php80 v1.18.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/var-dumper v4.4.15 Symfony mechanism for exploring and dumping PHP variables
不仅是上面这些例子,有很多例如OSS组件、图片处理组件、爬虫工具等都或多或少包含symfony组件,你可以通过composer info
命令查看当前项目使用的包,这里不一一列举了。由此可见,Symfony框架或其组件被使用得非常广泛,作为PHP开发者,我想我们非常值得去了解它的重要内容。
前面,我想通过查看composer包来告诉大家,symfony包使用是多么广泛,然而symfony之所以成为经典和学习的对象,绝不仅仅是它的包很多。关于这个我想日后再开新的章节进行讨论。这里我想走马观花地给大家列举一些可以快速使用到自己项目的包,这些包我都用过,并且取得很好的效果。
$_GET
或$_POST
之类的话,非常推荐你了解这个,能帮助你统一HTTP参数的获取操作。在我的项目经验里,见过非常多不规范的操作,比如任意位置直接修改$_GET
或$_POST
数组,导致其他成员无法获取到预期的数据。https://symfony.com/doc/current/components/http_foundation.htmlCopyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。