Related architecture design based on laravel4.2, laravel4.2 architecture design_PHP tutorial

WBOY
Release: 2016-07-13 10:16:09
Original
790 people have browsed it

Related architecture design based on laravel4.2, laravel4.2 architecture design

The project team introduced the laravel framework not long ago, and I participated in the research and project architecture design of laravel. I personally think that some designs based on Laravel in the project architecture are quite practical and useful for reference. Now I will share some designs with you, hoping to learn and discuss them with you. In particular, this article is not an excerpt or summary of lavarel's official documentation.

1Exception handling

1.1 Exception Class

Exception classes are placed under app/lib/exception and can be subdivided according to business modules. The abbreviated exception class can be in the form of multiple exception classes in one file, such as:

class HttpRequestException extends Exception

{

}

class HttpResponseException extends Exception

{

}

1.2 Capture Mechanism

Exception catching can be done wherever needed. If not caught, the exception will be thrown to the outermost layer.

For exceptions thrown to the outermost layer, the handler is defined in the app/start/global.php file

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 Throwing Mechanism

Exceptions can be thrown anywhere that can trigger exceptions.

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

if (!$content) {

throw new HttpRequestException($url . ':' . $data);

}

2 Log Record

There are three types of logs: interface call log (RequestLog), business log (LogicaltLog), and debugging log (DebugLog). The logs are placed in the app/lib/log directory. Among them, RequestLog can be used for statistical analysis of interface calls, LogicaltLog can be used to record logical data, and DebugLog can be used to output debugging information (you can also directly use the Log class that comes with laravel).

3 Task Queue

Laravle encapsulates Queue to be used as a task queue, which is very convenient for asynchronous processing. Supports: "sync", "beanstalkd", "sqs", "iron", "redis" five forms. It is recommended to use redis, it is super easy to use.

To use the queue, you only need to push the class name of the task class into the queue, and the task class implements the fire method, and it can be used.

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

Finally, a special reminder, you can start queue monitoring through the artisan tool of the laravel framework:

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

4 Filter

Filter can be used for parameter verification, login status check, and interface call log.

4.1 Parameter Check

Define the parameter verification conditions for each interface in app /config/param.php. Please refer to laravel documentation for verification conditions.

Then in Before of app/Filter.php, perform parameter verification for each call, 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

Usually, our framework will have several sets of environments: official, test, local, sandbox, etc. Different environment configurations will definitely be different. Laravel allows you to specify the current configuration environment when the process starts, thereby automatically switching between different environments.

1) Different environment configuration directories:

appconfigdev

appconfigformal

appconfiglocal

2) bootstrap/start.php specifies the required environment, such as test environment dev

$env = $app->detectEnvironment(‘dev’)

3) How to switch automatically?

We can specify the corresponding environment based on the different domain names accessed by the interface request. For example, dev.domain.com is the test environment, and domain.com is the official environment.

What is software system architecture design

Software architecture (software
architecture) is a series of related abstract patterns used to guide the design of all aspects of large software systems. Software architecture is a sketch of a system. The objects described by the software architecture are abstract components that directly constitute the system. The connections between components clearly and relatively detail describe the communication between components. In the implementation phase, these abstract components are refined into actual components, such as a specific class or object. In the object-oriented field, the connection between components is usually implemented using interfaces (Computer Science).
Software architecture is the basis for building computer software practice. Just as an architect sets the design principles and goals of a building project as the basis for a draftsman's drawings, a software architect or system architect states software architecture as the basis for actual system design solutions that meet various customer needs.
Software architecture is an easy-to-understand concept. Most engineers (especially those with little experience) will understand it intuitively, but it is difficult to give a precise definition. In particular, it is difficult to clearly distinguish between design and architecture: architecture is an aspect of design that focuses on certain specific features.
In "Introduction to Software Architecture", David Garlan and Mary Shaw
believe that software architecture is the design level related to the following issues: "In addition to computing algorithms and data structures, designing and determining the overall structure of the system has become a new issues. Structural issues include the overall organizational structure and global control structure; protocols for communication, synchronization, and data access; functional allocation of design elements; physical distribution; composition of design elements; scaling and performance; design alternatives Choice.
But architecture is more than just structure; the IEEE Working Group
on Architecture defines it as "the highest level concept of a system in its environment." Architecture also includes "compliance with" system integrity, economic constraints, and aesthetics. Requirements and styles. It not only pays attention to internal considerations, but also considers the system as a whole in the user environment and development environment of the system, that is, it also pays attention to external considerations in the Rational Unified Process. The architecture of a software system (at a given point) refers to the organization or structure of the important components of the system, which interact with the components composed of increasingly smaller components and interfaces through interfaces, purpose, and theme. In terms of the relationship between materials and structures, software architecture can be compared with the architecture of a building. A software architect needs to have extensive software theoretical knowledge and corresponding experience to realize and manage the high-level design of software products. Architects define and design software modularity, interactions between modules, user interface styles, external interface methods, innovative design features, and object operations, logic and processes for high-level things. Generally speaking, The architecture of a software system has two elements:
It is the highest-level division of a software system from the whole to its parts.
A system is usually composed of components, and how these components form and interact with each other. How it works is important information about the structure of the system itself.
Specifically, it includes Architecture Component, Connector, and Task-flow. The so-called architectural elements are the core "bricks" that make up the system, and the connector describes the communication path between these components, the communication mechanism, and the expected results of the communication. The task flow describes how the system uses these components and
The connector fulfills a certain requirement.
The highest-level, commercial and technical decision made in building a system that is difficult to change later.
There are many important decisions that need to be made in advance before building a system. Once the system begins to undergo detailed design or even construction, these decisions will be difficult or even impossible to change. Obviously, such decisions must be the most important decisions regarding the success or failure of the system design and must be studied and examined very carefully.




What is system design based on B/S architecture




First, what is the C/S structure.

C/S (Client/Server) structure, which is the well-known client and server structure. It is a software system architecture that can make full use of the advantages of the hardware environment at both ends and reasonably allocate tasks to the Client and Server sides, reducing the communication overhead of the system. At present, most application software systems
have a two-layer structure in the form of Client/Server. Since current software application systems are developing towards distributed Web applications, both Web and Client/Server applications can perform the same business processing. Different modules of applications share logical components; therefore, both internal and external users can access new and existing applications, and new applications can be extended through the logic in existing applications. This is the current development direction of application systems.

Although the traditional C/S architecture adopts an open model, this is only openness at the system development level. In specific applications, both the client and the server require specific software support. . Because it fails to provide the open environment that users really expect, software with a C/S structure needs to develop different versions of software for different operating systems. In addition, product updates are very fast, and it is difficult to adapt to the simultaneous use of more than a hundred computers on a LAN. . It is also costly and inefficient.

Second, what is the B/S structure.

B/S (Browser/Server) structure is the browser and server structure. It is a change or improved structure to the C/S structure with the rise of
Internet technology. Under this structure, the user work interface is implemented through the WWW browser. A very small part of the transaction logic is implemented on the front end
(Browser), but the main 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 workload of system maintenance and upgrades, and reduces the user's total cost of ownership (TCO).

Based on the current technology, establishing a network application with a B/S structure on a local area network
and using a database in Internet/Intranet mode is relatively easy to master and the cost is low. It is a one-time development that enables different personnel to access and operate a common database from different locations and through different access methods (such as LAN, WAN, Internet/Intranet, etc.); it can effectively The data platform and management access are well protected, and the server database is also secure. Especially after the emergence of cross-platform languages ​​​​such as JAVA, B/S architecture management software is even more convenient, fast and efficient.

Third, mainstream technology of management software.

The mainstream technology of management software technology, like management thought, has also gone through three development periods. First of all, interface technology has gone through three different development periods from the DOS character interface in the last century to the Windows graphical interface (or graphical user interface GUI) to the Browser browser interface. Secondly, the
browser interface of all computers today is not only intuitive and easy to use, but more importantly, the style of any application software based on the browser platform is the same. Users do not require high operating training, and the software It is highly operable and easy to identify; in addition, the platform architecture has also developed from a single user in the past to today's file/server (F/S) system, client/server (C/S) system and browser /Server (B/S) system.

2. Comparison between C/S and B/S

C/S and B/S are the two mainstream technologies in the development model technology architecture in the world today. C/S was first developed by the American Borland Company
, and B/S was developed by the American Microsoft Company. At present, these two technologies are mastered by countries around the world, and domestic companies have developed many products using C/S and B/S technologies. Both technologies have their own certain market share and customer base. Each company says that its management software architecture technology is powerful, advanced and convenient. They can cite their respective customer groups and have a large group of literati. The poets are waving flags and shouting for themselves, and advertisements are flying all over the sky, but
it can be said that benevolence has different opinions, and the wise... The rest of the full text >>




http://www.bkjia.com/PHPjc/898820.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/898820.htmlTechArticleBased on the related architecture design of laravel4.2, the laravel4.2 architecture design project team introduced the laravel framework not long ago. Participated in laravel research and project architecture design. Personally, I think the project frame...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template