(draft) Understanding Yii 3

You are viewing revision #14 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.

« previous (#13)

Understanding Yii 3

  1. Introduction
  2. Yii 3 composer packages
  3. Demo
  4. Guide and other docs

Introduction

This document is intended for an audience already familiar with Yii2. It's meant to bring together all information related to Yii 3 in one place to make it easier to get on track.

Yii 3 is the second major rewrite of the Yii framework.

Originally started in the 2.1 branch, it was later decided to switch to the 3.X series because of all the backward compatibility breakage. Starting with 3.0, Yii will follow the Sementic Versionning.

This rewrite addresses a lot of issues Yii 2 suffered from:

  • The framework being too coupled with jQuery, bower, bootstrap.
  • Big inheritance tree.
  • Non-standard objects behavior (magic properties).
  • Being out of the general PHP infrastructure with tons of extensions wrapping regular PHP code.
  • Being monolitic framework where you can not fine-tune by picking exactly what you need.
  • etc.
Source code splitting

The framework source code have been split into several packages, and at its core level, Yii no longer makes assumptions about your development stack, or the features you will be using.

This enable you to cherry pick the packages you need to compose your application.

This re-organisation is also a great news for maintainance, as these packages will be released separately, thus allowing more frequent updates.

Autoloading

The custom PHP class autoloader have been removed in favor of Composer's PSR-4 implementation. This means that in order for Yii to see your classes, you will have to explicitly register your namespace in composer.json. We will see an example later.

PSR compatibility

Yii 3 takes some positive steps following the PHP-FIG recommendations, by implementing the following PSRs:

  • Logging is now compliant with PSR-3
  • Caching is now compliant with PSR-16
  • Dependency Injection is now compliant with PSR-11
  • and more
Application configuration

If you've ever installed an extension using Yii 2, you may/certainly have found yourself on the extension README file, looking for the chunk of configuration to copy/paste in your own config/main.php file.

This can often lead to:

  • a huge configuration file (which you may have decided to split into smaller files)
  • non-trivials configurations update when a new version of the extension is realeased with new/changed configurations options.

Yii 3 takes another approach. Every package bundle its own configuration, and will probably work out of the box. And you may override them, if you need to, from your configuration file.

This is all done by leveraging the yiisoft/config, which takes care of scanning & merging all the configurations when you run composer dump-autoload (also know as composer du).

Packages authors will have the responsibility to avoid introducing BC breaks, by adopting a strict sementical versionning.

Dependency injection

Dependency injection is a core concept of Yii3. The team intentionally dropped service locator and used injection via type-hinting. You can learn more in the guide.

Yii 3 composer packages

Here are the new packages introduced in Yii 3, which can be found in this official list.

Demo

There are two demo apps available:

Guide and other docs

All the current documentation could be found in yiisoft/docs repository.

40 0
17 followers
Viewed: 200 038 times
Version: 3.0
Category: Tutorials
Tags: yii3
Written by: Mehdi Achour
Last updated by: samdark
Created on: Dec 16, 2018
Last updated: 2 years ago
Update Article

Revisions

View all history