官术网_书友最值得收藏!

Chapter 2. Organizing Code

Before we go further with CMS development, let's look at a problem that can be neatly solved using PHP5. Substantial systems do not consist of a single file of code. Whatever our exact design, a large system should be broken down into smaller elements, and it makes sense to keep them in separate files, if the language supports it. Code is more manageable this way, and systems can be made more efficient.

As we are considering only PHP implementations, the source code files are used at runtime. PHP is an interpreted language and, at least in principle, runs the actual source code. So we need a good technique for handling many source files at runtime.

This creates issues; a paramount one is security. Another is ease of coding, where it is tedious and cumbersome to have to repeatedly include code to load other files. Yet another is efficiency, as we do not want to load code that is not needed for a particular request.

The problem

Ideally we want an automated system for loading the correct code at the time it is needed. We need it to cater for a number of considerations such as:

  • Loading code in as few places as possible, as an aid to security
  • Avoiding programs needing to know whether code needs to be loaded
  • Only loading code that is being used
  • Providing a mechanism that will work for extensions beyond the basic system
主站蜘蛛池模板: 盐山县| 乐昌市| 伊宁市| 昌宁县| 留坝县| 苏尼特右旗| 甘谷县| 昌都县| 壤塘县| 阜新市| 离岛区| 蓬溪县| 长武县| 清徐县| 饶阳县| 溆浦县| 玉田县| 涟源市| 宜昌市| 鲜城| 莒南县| 贡嘎县| 南康市| 兴安县| 丰台区| 长兴县| 桃源县| 扶风县| 石河子市| 汶上县| 台安县| 油尖旺区| 离岛区| 龙胜| 丹棱县| 灌云县| 丰镇市| 江津市| 丽水市| 夏河县| 兖州市|