You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

architecture.md 3.1 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Architecture
  2. ## Schematical
  3. ![01-schematic.png](./images/01-schematic.png "Basic Architecture Schematic")
  4. ## AutoLoader
  5. PhpSpreadsheet relies on Composer autoloader. So before working with
  6. PhpSpreadsheet in standalone, be sure to run `composer install`. Or add it to a
  7. pre-existing project with `composer require phpoffice/phpspreadsheet`.
  8. ## Spreadsheet in memory
  9. PhpSpreadsheet's architecture is built in a way that it can serve as an
  10. in-memory spreadsheet. This means that, if one would want to create a
  11. web based view of a spreadsheet which communicates with PhpSpreadsheet's
  12. object model, he would only have to write the front-end code.
  13. Just like desktop spreadsheet software, PhpSpreadsheet represents a
  14. spreadsheet containing one or more worksheets, which contain cells with
  15. data, formulas, images, ...
  16. ## Readers and writers
  17. On its own, the `Spreadsheet` class does not provide the functionality
  18. to read from or write to a persisted spreadsheet (on disk or in a
  19. database). To provide that functionality, readers and writers can be
  20. used.
  21. By default, the PhpSpreadsheet package provides some readers and
  22. writers, including one for the Open XML spreadsheet format (a.k.a. Excel
  23. 2007 file format). You are not limited to the default readers and
  24. writers, as you are free to implement the
  25. `\PhpOffice\PhpSpreadsheet\Reader\IReader` and
  26. `\PhpOffice\PhpSpreadsheet\Writer\IWriter` interface in a custom class.
  27. ![02-readers-writers.png](./images/02-readers-writers.png "Readers/Writers")
  28. ## Fluent interfaces
  29. PhpSpreadsheet supports fluent interfaces in most locations. This means
  30. that you can easily "chain" calls to specific methods without requiring
  31. a new PHP statement. For example, take the following code:
  32. ``` php
  33. $spreadsheet->getProperties()->setCreator("Maarten Balliauw");
  34. $spreadsheet->getProperties()->setLastModifiedBy("Maarten Balliauw");
  35. $spreadsheet->getProperties()->setTitle("Office 2007 XLSX Test Document");
  36. $spreadsheet->getProperties()->setSubject("Office 2007 XLSX Test Document");
  37. $spreadsheet->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
  38. $spreadsheet->getProperties()->setKeywords("office 2007 openxml php");
  39. $spreadsheet->getProperties()->setCategory("Test result file");
  40. ```
  41. This can be rewritten as:
  42. ``` php
  43. $spreadsheet->getProperties()
  44. ->setCreator("Maarten Balliauw")
  45. ->setLastModifiedBy("Maarten Balliauw")
  46. ->setTitle("Office 2007 XLSX Test Document")
  47. ->setSubject("Office 2007 XLSX Test Document")
  48. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  49. ->setKeywords("office 2007 openxml php")
  50. ->setCategory("Test result file");
  51. ```
  52. > **Using fluent interfaces is not required** Fluent interfaces have
  53. > been implemented to provide a convenient programming API. Use of them
  54. > is not required, but can make your code easier to read and maintain.
  55. > It can also improve performance, as you are reducing the overall
  56. > number of calls to PhpSpreadsheet methods: in the above example, the
  57. > `getProperties()` method is being called only once rather than 7 times
  58. > in the non-fluent version.