laravel4.2-based architecture design, laravel4.2 architecture Design _php Tutorials

Source: Internet
Author: User

laravel4.2-based architecture design, laravel4.2 architecture design

The project team recently introduced the Laravel framework, and I participated in the Laravel Research and project architecture design. I think the project structure based on Laravel some of the design is more practical and reference, and now some design to share to everyone, and we hope to learn and discuss together. In particular, this article does not extract or summarize the official documents of Lavarel.

1 Exception handling

1.1 Exception classes

Exception class unified under the App/lib/exception, can be subdivided according to the business module, the exception class for shorthand can take a file multiple exception class form, such as:

Class Httprequestexception extends Exception



Class Httpresponseexception extends Exception



1.2 Capture mechanism

You can do an exception capture wherever you want, and if you don't, the exception will be thrown to the outermost layer.

Thrown to the outermost exception, unified in the app/start/global.php file definition handler

function HandleException ($code, $exception)


Return decorate::failed ($code, NULL, $exception->getfile (). ':' . $exception->getline (). ',' . $exception->getmessage ());


App::error (function (httprequestexception $exception, $code)


Return HandleException ( -1007, $exception);


App::error (function (httpresponseexception $exception, $code)


Return HandleException ( -1008, $exception);


1.3 Throw mechanism

An exception can be thrown where any exception can be triggered.

Requestlog::request ($url, $data, $start, $content);

if (! $content) {

throw new Httprequestexception ($url. ':' . $DATA);


2 Log records

There are three types of log: interface call log (requestlog), business log (logicaltlog), debug log (Debuglog). The log is uniformly placed under the App/lib/log directory. Where requestlog can be used for the statistical analysis of interface calls, Logicaltlog can be used to record logical data, Debuglog for output debugging information (also directly with Laravel \log Class).

3 Task Queue

Laravle encapsulates the queue used to do task queues and is very handy for asynchronous processing. Support: "Sync", "BEANSTALKD", "SQS", "Iron", "Redis" five forms. Redis is recommended, super easy to use.

The queue usage method simply presses the class name of the task class into the queue, and the task class implements the fire method, which can be used.

In the Fire ($job, $data), we can also get the number of attempts $job->attempts (), can delay the task response time $job->release (30), you can also delete the task $job->delete ();.

Finally, you can start the queue monitoring via the Laravel Framework's artisan tool:

Php.. /.. /.. /.. /artisan--env=devqueue:listen&

4 Filter

Filter can be used to do parameter verification, login state check, interface call log.

4.1 Parameter checking

The parameter validation conditions for each interface are defined in the app/config/param.php. The validation criteria refer to the Laravel documentation yourself.

Then, in App/filter.php's before, parameters are validated for each invocation, such as:

App::before (function ($request))



$res = Param::verification (Input::all (), $standard);



4.2 Interface Call Log

App::after (function ($request, $response)



Requestlog::log ($request, $response);



5 Environment switching

In general, our framework will have several sets of environments: formal, test, local, sandbox, etc., different environment configuration will certainly be different. Laravel allows the current configuration environment to be specified at the start of the process, enabling automatic switching between different environments.

1) Different Environment configuration directory:




2) bootstrap/start.php Specify the desired environment, such as test environment dev

$env = $app->detectenvironment (' Dev ')

3) How to switch automatically?

We can specify the appropriate environment depending on the domain name that the interface requests to access. For example, is a test environment, is a formal environment.

What is software system architecture design

Software Architecture (software
Architecture) is a series of related abstract patterns designed to guide the design of large software systems in all its aspects. Software architecture is a sketch of a system. Software architecture describes the object is directly composed of the system
The abstract components of the system. The connections between the components describe the communication between the components clearly and in a relatively detailed manner. In the implementation phase, these abstract components are subdivided into actual components, such as a specific class or object. In the face of
In the domain of objects, connections between components are usually implemented using interfaces _ (computer science).
Software architecture is the foundation of building computer software practice. With architects setting design principles and objectives for building projects, as the basis for graphing, a software architect or system architect presents the software architecture as the basis for a practical system design that meets the needs of different customers.
Software architecture is an easy-to-understand concept, and most engineers (especially inexperienced engineers) know it intuitively, but it is difficult to give precise definitions. In particular, it is difficult to clearly differentiate between design and architecture: The architecture is part of the design, and it concentrates on certain specific features.
In the introduction to software architecture, David Garlan and Mary Shaw
It is considered that the software architecture is the design level of the following problems: "In addition to the computational algorithms and data structures, it is a new problem to design and determine the overall structure of the system." Structural problems include overall organizational structure and global control knot
Communication, synchronization and data access protocols, functional allocation of design elements, physical distribution, composition of design elements, calibration and performance, alternative design options.
But the framework is not just a structure; IEEE working Group
On Architecture defines it as "the system's highest-level concept in its environment." The framework also includes "conforming" to system integrity, economic constraints, aesthetic needs and patterns. It does not only note
The internal considerations, but also in the user environment and development environment of the system to consider the overall system, that is, at the same time focus on external considerations.
In rational Unified Process, the architecture of a software system (at a given point) refers to the organization or structure of an important component of the system, which interacts with the components of the component and interface that are being reduced by the interface.
The software architecture can be compared to the architecture of a building in relation to its purpose, subject, material and structure. A software architect needs to have extensive software theory knowledge and corresponding experience to the facts and the tube
High-level design of software products. Software architects define and design software modularity, interaction between modules, user interface styles, external interface methods, innovative design features, and object manipulation of high-level objects, logic
and processes.
In general, the architecture of the software system (Architecture) has two elements:
It is a software system that divides from whole to part of the highest level.
A system is usually composed of components, and how these components are formed and how they interact with each other is an important information about the structure of the system itself.
In detail, it is to include the architecture element (Architecture Component), the coupler (Connector), the task flow (Task-flow).
The so-called architectural elements, which are the core "bricks" of the system, and the coupler describe the communication path between these components, the mechanism of communication, the expected results of communication, the task flow describes how the system uses these components and
The coupler completes a requirement.
The highest level, hard-to-change, commercial, and technological decisions made by the construction of a system.
There are many important decisions that need to be made prior to building a system, and once the system has been designed and even built, these decisions can be difficult to change or even change. Obviously, such a decision must be the most important decision about the success or failure of the system design, it has to undergo very careful research and investigation.

What is the system design based on B/S architecture

First, what is the C/s structure.

c/S (CLIENT/SERVER) structure, known as the client and server structure. It is a software system architecture, which can make full use of the advantages of both ends of the hardware environment, the task is reasonably distributed to the client side and server side to achieve, reducing the communication overhead of the system. Most application software systems currently
System are client/server form of two-layer structure, because the current software applications are developing to distributed Web applications, both Web and client/server applications can do the same business processing, the application of different modules to share the logical components; Both internal and external users have access to new and existing applications, and new applications can be extended through the logic of existing applications. This is the current application system development direction.

Although the traditional C/S architecture adopts the open mode, it is only the openness of the system development level, and the specific software support is also needed in the specific application either client side or server side. Due to the lack of a user's real expectations of the open environment, C/s structure of software needs for different operating system systems to develop different versions of the software, coupled with the rapid upgrading of products, has been difficult to adapt to hundreds of computers over LAN users at the same time. And the cost is high and the efficiency is low.

Second, what is the B/s structure.

The b/S (BROWSER/SERVER) structure is the browser and server structure. It is with
The rise of Internet technology, a change of C/s structure or an improved structure. In this structure, the user interface is implemented by WWW browser, very few transaction logic in the front
(Browser) Implementation, but the primary transaction logic is implemented on the server side (server), forming the so-called three-layer 3-tier structure. This greatly simplifies the client computer load, reduces the cost and effort of system maintenance and upgrade, and reduces the total cost of users (TCO).

With the present technology, the network of B/s structure of LAN should be
Use, and through the Internet/intranet mode database application, relatively easy to grasp, the cost is also low. It is a one-time in-place development that can achieve different people from different ground
Access and operation of a common database with different access methods (such as lan,wan,internet/intranet, etc.), which can effectively protect the data platform and manage access rights,
Database is also secure. In particular, after the emergence of a cross-platform language such as Java, b/s architecture management software is convenient, fast and efficient.

Third, management software mainstream technology.

The mainstream technology of management software technology and management thought, also experienced three period of development. First, the interface technology from the last century DOS character interface to the Windows graphical interface (or GUI), until the browser browser interface three different development period. Second, all of today's computers
Browser interface, not only intuitive and easy to use, but also the main browser-based platform of any application software its style is the same, the user of the operation of training requirements are not high, and the software is highly operational, easy to recognize
In addition, the platform architecture has evolved from the past single user to today's file/server (F/S) system, client/server (c/s) system and browser/server (b/s) system.

Ii. Comparison of c/S and b/s

c/S and b/s are the two main mainstream technologies for the development model technology architecture in the world today. c/S is an American Borland company
The first research and development, b/S is the United States Microsoft Company. At present, these two technologies to be mastered by the countries around the world, domestic companies to C/s and B + + technology to develop a wide range of products. Both of these technologies have a certain market
Market share and customer base, each enterprise said their management software architecture technology powerful, advanced, convenient, can cite their respective customer groups, there is a large group of literati for their own banner, advertising, can
The wisdom of the beholder ... Remaining full text >> true techarticle based on the laravel4.2 architecture design, laravel4.2 Architecture design project team recently introduced the Laravel framework, I participated in the Laravel Research and project architecture design. Personal view of the project stand ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.