symfony_Symfony在Drupal 8中

symfony

If you are a Drupaler, you must be aware that Drupal 8 is on the way. What you may not know is that it includes a few important Symfony components. Working with Drupal 8.x will give Drupalers an opportunity to become a part of a massive learning curve and is going to tempt them to know more about Symfony. In this article, we discuss the Symfony components that have been added to Drupal 8, covering some third party libraries along the way.

如果您是Drupaler,则必须知道Drupal 8即将推出。 您可能不知道的是,它包含一些重要的Symfony组件。 使用Drupal 8.x将使Drupalers有机会成为大规模学习曲线的一部分,并将诱使他们更多地了解Symfony。 在本文中,我们讨论了已添加到Drupal 8中的Symfony组件,涵盖了一些第三方库。

Before we get into the actual article, let us first briefly cover Symfony. It is a PHP based web application framework that follows the MVC architecture. Moreover, it is an open source project that has been released under the MIT license. Please make sure you don’t get it confused with Symfony CMS. If you wish to explore the Symfony framework into greater detail, see its Wiki page or any of the previous SitePoint articles about it.

在进入实际文章之前,让我们首先简要介绍一下Symfony 。 它是遵循MVC架构的基于PHP的Web应用程序框架。 此外,它是一个开放源代码项目,已根据MIT许可发布。 请确保您不要将它与Symfony CMS混淆。 如果您想更详细地探索Symfony框架 ,请参阅其Wiki页面有关它的以前的SitePoint文章

Now let’s learn about the Symfony components that are being implemented in Drupal 8.

现在让我们了解在Drupal 8中实现的Symfony组件。

Drupal 8.x中的Symfony组件 (Symfony components in Drupal 8.x)

The following are the Symfony components that are going to power the Drupal 8 core to a major extent:

以下是将在很大程度上为Drupal 8核心提供动力的Symfony组件:

  • HttpKernel and HttpFoundation – These are responsible for streamlining the process of converting a Request into a Response with the help of EventDispatcher. Drupal 8 being moved to Symfony was driven by Web Services and Content Core Initiative (WSCCI) in a motive to transform Drupal from a first-class CMS to a first-class REST server with first-class CMS running on top of it. This initiative is intended to allow Drupal to use web services to offer its content with reduced complexity; considering this as a long term vision, Drupal will be more flexible, robust and easily maintainable CMS.

    HttpKernelHttpFoundation –负责借助EventDispatcher简化将请求转换为响应的过程。 由Web服务和内容核心计划(WSCCI)驱动的Drupal 8迁移到Symfony的动机是,将Drupal从一流的CMS转变为一流的 REST服务器,并在其之上运行一流的CMS。 该计划旨在使Drupal能够使用Web服务以降低复杂性的方式提供其内容; 考虑到这是一个长远的愿景,Drupal将成为更加灵活,强大和易于维护的CMS。

  • EventDispatcher – Implements the Mediator pattern (that uses encapsulation) in a simple and effective manner especially where code inheritance doesn’t work out, making the application highly extensible. It is more effective in situations where you tend to maintain and/or refactor a program consisting of a huge number of classes due to the fact that it makes the communication amongst the classes quite simple and easy.

    EventDispatcher –以简单有效的方式实现Mediator模式 (使用封装),尤其是在代码继承无法解决的情况下,从而使应用程序具有高度可扩展性。 在您倾向于维护和/或重构包含大量类的程序的情况下,这种方法更为有效,因为它使类之间的通信变得非常简单和容易。

  • ClassLoader – Provides tools that autoload classes and caches their location. PHP uses the autoloading mechanism to delegate the loading of a file that defines the class in situations where you reference a class that has not been required or included yet. Symfony comes with autoloaders like PSR-0 Class Loader and MapClassLoader. Implementing the ClassLoader component will make Drupal module developers carefree especially when it comes to implementing module_load_include and other dependencies. Moreover, it allows developers easy calling of classes during run-time.

    ClassLoader –提供自动加载类并缓存其位置的工具。 PHP使用自动加载机制来委托在定义了不需要或不包含的类的情况下定义该类的文件的加载。 Symfony附带了PSR-0 Class LoaderMapClassLoader等自动加载器。 实现ClassLoader组件将使Drupal模块开发人员无忧无虑,尤其是在实现module_load_include和其他依赖项时。 而且,它允许开发人员在运行时轻松地调用类。

  • YAML – It parses YAML strings and converts them to PHP arrays and vice versa. This format has been especially designed to hold configuration related information, while being as expressive as XML files and as readable as INI files. It serves as an integral component of Drupal’s CMI (Configuration Management Initiative) that allows our modules to initially define their default configuration settings and later allows the site builder to override the same as-and-when instructed to. This concept of Drupal 8’s CMI which is powered by YAML is a replacement for Features contributed Drupal module which proves to be a robust concept as far as migrating and deploying across environments is concerned.

    YAML –解析YAML字符串并将其转换为PHP数组,反之亦然。 该格式经过专门设计,可保存与配置有关的信息,同时具有与XML文件一样的表现力和与INI文件一样的可读性。 它是Drupal的CMI (配置管理计划)的组成部分,它允许我们的模块最初定义其默认配置设置,后来允许站点构建者按要求覆盖相同的内容。 由YAML提供支持的Drupal 8的CMI概念替代了Features贡献的Drupal模块 ,事实证明,就跨环境迁移和部署而言, Drupal模块是一个可靠的概念。

  • Routing – Allows us to load all routes, and dumps a URL matcher or generator specific to these routes. This also means that it maps an HTTP request to a set of configuration variables. As far as Drupal 8 and above versions are concerned, we define our module’s routes in a YAML configuration file, each of them set to trigger a specific action that has been defined in our module’s classes.

    路由 -允许我们加载所有路由,并转储特定于这些路由的URL匹配器或生成器。 这也意味着它将HTTP请求映射到一组配置变量。 就Drupal 8及更高版本而言,我们在YAML配置文件中定义了模块的路由,每个路由都设置为触发在模块类中定义的特定操作。

  • DependencyInjection – Primarily used to standardize and centralize the way objects are constructed in our application. Symfony’s DependencyInjection component has been incorporated in Drupal 8 in an intention to write code in such a way that classes can be reused and unit-tested wherever applicable and desired.

    DependencyInjection –主要用于标准化和集中化应用程序中对象构造的方式。 Symfony的DependencyInjection组件已合并到Drupal 8中,目的是编写代码,以便可以在适用和需要的地方重用和进行类测试。

  • Twig – Drupal 8 has adopted the Twig template engine. This is of interest to the themers who will probably never think of any other option again for as long as they’re working on Drupal themes. Twig was developed by Fabien Potencier, who also developed the Symfony project, and was fine tuned for integration into Drupal 8.

    Twig – Drupal 8采用了Twig模板引擎。 这些主题使那些感兴趣的人感兴趣,只要他们正在研究Drupal主题,他们就永远不会再考虑任何其他选择。 Twig由Fabien Potencier开发,他还开发了Symfony项目 ,并进行了微调以集成到Drupal 8中。

  • Process – Helps execute commands in sub-processes using the command-line interface. Drupal 8 will use this to handle all activities that are command-line in nature.

    流程 –使用命令行界面帮助在子流程中执行命令。 Drupal 8将使用它来处理本质上是命令行的所有活动。

  • alt

    Serializer – It is used to transform objects into a specific format (eg. XML, YAML, JSON, etc.) and vice versa. To understand it better, let us look at the following schema that a Serializer component follows:

    序列化器 –用于将对象转换为特定格式(例如XML,YAML,JSON等),反之亦然。 为了更好地理解它,让我们看一下序列化器组件遵循的以下架构:

    Additionally, we can use it to accomplish a number of jobs, ranging from configuration to node and entity creation that should be delivered by a REST endpoint.

    另外,我们可以使用它来完成许多工作,从配置到节点和实体创建,这些工作都应该由REST端点交付。

  • Validator – Helps Drupal validate values. For example: validating form submission, validating entities within Drupal, etc. To accomplish its job, it uses Doctrine Annotations (discussed in Out-of-the-box third party components section).

    验证器 –帮助Drupal验证值。 例如:验证表单提交,验证Drupal中的实体等。为了完成其工作,它使用“学说注释” (在即用的第三方组件部分中讨论)。

  • Translation – Provides a standard set of tools to load translation files, generate translated strings as output, and use the generated outcome.

    翻译 –提供一组标准工具来加载翻译文件,生成翻译后的字符串作为输出以及使用生成的结果。

开箱即用的第三方组件 (Out-of-the-box third party components)

We went through Symfony components that have been included with Drupal 8. In this section, we’ll find out about the 3rd party PHP components that have been implemented in Drupal 8 and are not related to Symfony. They are:

我们研究了Drupal 8随附的Symfony组件。在本节中,我们将了解在Drupal 8中实现的与Symfony无关的第三方PHP组件。 他们是:

  • Assetic – An Asset Management framework. Assets in Drupal consist of CSS files, JavaScript files, images, other media files, metadata, etc. These assets contain filterable content that can be loaded and dumped. In order to manipulate assets, you need to apply appropriate filters. To understand the filters, in what situations each can be used, how-to use the filters, build, dump, and much more, we recommend you read the Assetic Github page.

    Assetic - 资产管理框架 。 Drupal中的资产由CSS文件,JavaScript文件,图像,其他媒体文件,元数据等组成。这些资产包含可加载和转储的可过滤内容。 为了操纵资产,您需要应用适当的过滤器。 要了解过滤器,在什么情况下可以使用每种过滤器,如何使用过滤器,构建,转储等等,我们建议您阅读Assetic Github页面

  • Composer – A tool specifically designed and developed to manage dependency in PHP allowing us to declare the dependent libraries our project needs and install them for us. Though it deals in packages and libraries, it is not a package manager. Composer is a boon to Drupal 8 due the following:

    Composer –专为开发和管理 PHP中的依赖关系而设计和开发的工具,使我们能够声明项目所需的依赖库并为我们安装它们。 尽管它处理软件包和库,但它不是软件包管理器。 Composer得益于Drupal 8:

    • Handles situations very efficiently wherein your project is dependent upon a number of libraries.

      非常有效地处理您的项目依赖于许多库的情况。

    • Tackles situations where there is a nested dependency concept amongst the libraries. For instance; your project is dependent upon a library (say, lib1) and in tern lib1 is dependent upon some other library (say, lib2).

      解决在库之间存在嵌套依赖项概念的情况。 例如; 您的项目依赖于一个库(例如, lib1 ),而lib1则依赖于其他某个库(例如, lib2 )。

    • It is Composer’s responsibility to choose which version of the package or library needs to be installed unless explicitly told which versions to target.

      除非明确告知要定位的版本,否则Composer的责任是选择需要安装软件包或库的哪个版本。

  • Doctrine – A bundle of tools for use with database records. Drupal 8 uses a part of it called Annotations that exposes additional metadata to Drupal. Efforts have been made to present such tricky functionality in a quite easy and handy way, especially when defining custom entity types. If you wish to explore further on how Doctrine is supposed to be used with Drupal 8, we recommend you visit the documentation page.

    原则 –一整套用于数据库记录的工具。 Drupal 8使用它的一部分,称为Annotations ,它将其他元数据公开给Drupal。 已经做出努力以相当容易和方便的方式呈现这种棘手的功能,尤其是在定义自定义实体类型时。 如果您想进一步研究Drupal 8应该如何使用Doctrine,我们建议您访问文档页面

  • EasyRDF – A PHP library that has been used with Drupal 8 so as to provide ease in consuming and producing RDF. With the help of EasyRDF, Drupal 8 adds capability to produce metadata in the markup in an easy and convenient way. You may also visit EasyRDF official site to learn more about it.

    EasyRDF –一个PHP库,已与Drupal 8一起使用,以简化使用和生产RDF的过程。 在EasyRDF的帮助下,Drupal 8添加了以简单便捷的方式在标记中生成元数据的功能。 您也可以访问EasyRDF官方网站以了解更多信息。

  • Guzzle – It is a PHP HTTP client and framework that helps Drupal 8 make web requests using REST based web service calls. This makes Drupal 8 web portals more efficient in terms of handling different sorts of web services. To explore further on Guzzle, we recommend reading our previous article on it.

    Guzzle –它是一个PHP HTTP客户端和框架,可帮助Drupal 8使用基于REST的Web服务调用来发出Web请求。 这使得Drupal 8 Web门户在处理各种Web服务方面更加高效。 要进一步研究Guzzle,建议您阅读之前的文章

  • PHPUnit – Used in Drupal 8 to standardize unit testing throughout the core as well as help developers write code that is of utmost quality. PHPUnit ensures that any code written in Drupal 8 and in any custom module incorporated in it matches industry standards and works as expected throughout its life-cycle. You may keep an eye on the current status of PHPUnit’s incorporation into Drupal 8 by going here.

    PHPUnit –在Drupal 8中用于标准化整个核心的单元测试,并帮助开发人员编写最高质量的代码。 PHPUnit确保以Drupal 8编写的任何代码以及包含在其中的任何自定义模块中的任何代码均符合行业标准,并在其整个生命周期中都能正常工作。 您可以通过此处随时了解PHPUnit并入Drupal 8的当前状态。

  • PSR-3 Logging – A common logging system that is shared by an entire PHP application. Drupal 7 and older versions use watchdog() for this purpose. Switching Drupal logging from watchdog() to a PSR-3 logging framework has made Drupal 8 more robust and scalable in terms of common logging. You may track the current status of this component at Switch watchdog to a PSR-3 logging framework.

    PSR-3日志记录 –整个PHP应用程序共享的通用日志记录系统。 Drupal 7和更早的版本为此使用watchdog() 。 将Drupal日志记录从watchdog()切换到PSR-3日志记录框架,使Drupal 8在普通日志记录方面更加强大和可扩展。 您可以在Switch Watchdog到PSR-3日志记录框架中跟踪此组件的当前状态

结论 (Conclusion)

The introduction of a few Symfony components has simplified working with Drupal 8. Additionally, including a few of the non-Symfony components has added value to Drupal 8 in terms of its quality, scalability, and performance, making it even more robust and maintainable.

一些Symfony组件的引入简化了Drupal 8的工作。此外,包括一些非Symfony组件在质量,可伸缩性和性能方面为Drupal 8增添了价值,使其更加健壮和可维护。

翻译自: https://www.sitepoint.com/symfony-drupal-8/

symfony

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值