최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday

티스토리 뷰

설계




개요


Lazy Loader

일반적으로 그것이 필요되는 시점까지 연기하여 프로그램의 작업 효율을 늘리는 것이다. 

즉 지연로드. (반대어:즉시로드)




PHPExcel은 오토로더 혹인 lazy loader를 구현한다, 이 말은 PHPExcel내에서 모든 파일을 포함할 필요가 없다는 것을 의미한다.


오직 필요한 PHPExcel클래스파일만을 포함하여 초기화 시킨다. 오토로더는 다른 클래스 파일이 필요한 경우에만 인클루드한다.


그래서 실제 스크립트를 위한 해당 파일은 PHP메모리에 로드된다.


이것의 주요 장점은 PHPExcel 자체의 메모리 사용량을 줄이고 PHP가 적은 메모리를 사용할수 있도록 한다.


만약 자신이 직접 자동로드 기능 스크립트를 이미 정의하였다면, PHPExcel의 자동로드기능을 덮어쓸 수 있다.


예를들어 당신이 가지고있는 코드가 다음과 같을 경우


function __autoload($class) {

    ...

}


Do this instead : 대신 이 작업을 수행합니다.


function myAutoload($class) {

    ...

}


* Your autoloader will then co-exist with the autoloader of PHPExcel. 오토로더는 PHPExcel의 오토로더와 공존한다.



메모리의 스프레드 시트


PHPExcel의 아키텍처는 메모리에 스프레드시트를 포함할수 있도록 내장되어있다.


이 의미는, 만약 PHPExcel객체의 모델과 통신하는 웹 기반 스프레드시트 뷰를 만드려면


단지 프론트엔드 코드만 작성하면 된다.


일반적인 데스크탑 스프레드시트 소프트웨어의 경우, PHPExcel은 한개 혹은 복수개의 워크 시트를 포함하는 스프레드시트를 나타내며 


셀의 정보에는 데이터와 수식, 이미지를 포함한다.



읽기와 쓰기


PHPExcel 자체로는 스프레드 시트(디스크 혹은 데이터베이스에 위치한)를 읽거나 기록하는 기능을 제공하지 않는다.


읽기와 쓰기를 사용할 수 있긴 있는데


기본적으로 PHPExcel패키지는 오픈XML스프레드 시트형식(일명 엑셀2007 파일 혀익)에 대해 읽기와 쓰기를 제공하며


읽기와 쓰기에 국한된것이 아니라 PHPExcel_Writer_IReader 와 PHPExcel_Writer_IWriter 인터페이스를 사용하여


자유롭게 커스텀 클래스를 구현할 수 있다.




인터페이스 구사


PHPExcel은 대부분의 환경에서 인터페이스를 지원한다.


이 말은 체인 특정 방법에 대해 쉽게 체인을 호출하고 새로운 PHP구문이 필요하지 않다.


다음의 예를 들어보자 코드를 살펴보면

 

$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
$objPHPExcel->getProperties()->setCategory("Test result file");


This can be rewritten as: 이 코드는 다음과 같이 다시 작성할 수 있습니다.


$objPHPExcel->getProperties()
    ->setCreator("Maarten Balliauw")
    ->setLastModifiedBy("Maarten Balliauw")
    ->setTitle("Office 2007 XLSX Test Document")
    ->setSubject("Office 2007 XLSX Test Document")
    ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
    ->setKeywords("office 2007 openxml php")
    ->setCategory("Test result file");


굳이 인터페이스를 사용하는 것은 필요하지 않다.


인터페이스는 편리한 프로그래밍 API를 제공하기 위해서 구현되었다. 


코드의 가독성과 유지보수의 목적 아니라면 그것들의 사용은 필요하지 않다.


이것은 또한 성능 향상으로 이어져, PHPExcel 메서드의 전체 호출을 줄일 수 있다.


위의 예제는 getProperties() 메서드를 한번만 호출하고 7개 모두 인터페이스 모드가 아닌것을 알 수 있다.




영어원문


Architecture

Schematical



Lazy Loader

PHPExcel implements an autoloader or "lazy loader", which means that it is not necessary to include every file within PHPExcel. It is only necessary to include the initial PHPExcel class file, then the autoloader will include other class files as and when required, so only those files that are actually required by your script will be loaded into PHP memory. The main benefit of this is that it reduces the memory footprint of PHPExcel itself, so that it uses less PHP memory.

If your own scripts already define an autoload function, then this may be overwritten by the PHPExcel autoload function. For example, if you have:

function __autoload($class) {
    ...
}

Do this instead:

function myAutoload($class) {
    ...
}

spl_autoload_register('myAutoload');

Your autoloader will then co-exist with the autoloader of PHPExcel.

Spreadsheet in memory

PHPExcel's architecture is built in a way that it can serve as an in-memory spreadsheet. This means that, if one would want to create a web based view of a spreadsheet which communicates with PHPExcel's object model, he would only have to write the front-end code.

Just like desktop spreadsheet software, PHPExcel represents a spreadsheet containing one or more worksheets, which contain cells with data, formulas, images, ...

Readers and writers

On its own, PHPExcel does not provide the functionality to read from or write to a persisted spreadsheet (on disk or in a database). To provide that functionality, readers and writers can be used.

By default, the PHPExcel package provides some readers and writers, including one for the Open XML spreadsheet format (a.k.a. Excel 2007 file format). You are not limited to the default readers and writers, as you are free to implement the PHPExcel_Writer_IReader and PHPExcel_Writer_IWriter interface in a custom class.



Fluent interfaces

PHPExcel supports fluent interfaces in most locations. This means that you can easily "chain"" calls to specific methods without requiring a new PHP statement. For example, take the following code:

$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
$objPHPExcel->getProperties()->setCategory("Test result file");

This can be rewritten as:

$objPHPExcel->getProperties()
    ->setCreator("Maarten Balliauw")
    ->setLastModifiedBy("Maarten Balliauw")
    ->setTitle("Office 2007 XLSX Test Document")
    ->setSubject("Office 2007 XLSX Test Document")
    ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
    ->setKeywords("office 2007 openxml php")
    ->setCategory("Test result file");

Using fluent interfaces is not required
Fluent interfaces have been implemented to provide a convenient programming API. Use of them is not required, but can make your code easier to read and maintain.

It can also improve performance, as you are reducing the overall number of calls to PHPExcel methods: in the above example, the getProperties() method is being called only once rather than 7 times in the non-fluent version.


source : https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/02-Architecture.md

댓글