PHP Objects, Patterns, and Practice- P12

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:15

0
60
lượt xem
6
download

PHP Objects, Patterns, and Practice- P12

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

PHP Objects, Patterns, and Practice- P12: This book takes you beyond the PHP basics to the enterprise development practices used by professional programmers. Updated for PHP 5.3 with new sections on closures, namespaces, and continuous integration, this edition will teach you about object features such as abstract classes, reflection, interfaces, and error handling. You’ll also discover object tools to help you learn more about your classes, objects, and methods.

Chủ đề:
Lưu

Nội dung Text: PHP Objects, Patterns, and Practice- P12

  1. ■ INDEX naming collisions, 71, 74 centralizing common classes used in nested namespaces, declaring, 73 multiple projects, 455 PHP 5.3 and, 14, 71 class switching, 106 phpDocumentor and, 353 code duplication, 109, 454 relative namespaces, 74 code smells, 109 require_once(), 76 coding to an interface, 141, 457 switching to global space within a file, 76 cohesion, definition of, 104 unqualified name, 73 comparing to procedural programming, use keyword, 74 100, 103 using a domain name as a namespace, 73 Conf class, code listing, 51 using braces with the namespace keyword, constant properties, 44 75 Continuous Integration (CI), 460 using the as clause with use, 75 controller, 454 NastyBoss class, 146–147 copying objects with __clone(), 63 new operator, 16, 21 coupling in, 104 newInstance(), 96 create_function(), 67–68 newSelection(), 310 declaring a class or method final, 57 newUpdate(), 309–310 decoupling, definition of, 454 next(), 477 defining string values for objects, 65 nextToken(), 472–473, 477 defining the boundaries of classes, 105 Nock, Clifton, 298, 311 delegating object instantiation, 147 notes element, 336 describing a class’s responsibility, 105 Notifier class, 140 designing child classes to provide notify(), 204–205 specialized functionality, 132 notifyAccess(), 282, 298 destructor methods, 62 notifyError(), 333 devising strategies for object generation, 145, 147 notifyPasswordFailure(), 389 DomainObject class, 49 null, using in hinted arguments, 27 Employee class, 146, 148 encapsulating the concept that varies, 458 ■O encapsulation, 107–108 object lifelines, 117 Factory Method pattern, 152 object types, 25 factory, definition of, 44, 148 object-oriented design favoring composition over inheritance, 132 abstract classes, 45 final keyword, 57 Abstract Factory pattern, 157 focusing on the metasystem, 458 abstract types as enabling polymorphism, Fowler, Martin, 110 146 getAllParams(), 102 addEmployee(), 147 getInstance(), 44, 102, 104, 149 addParam(), 102 global variables, 149, 454 aesthetics of, 455 instantiating objects as a dirty business, 147 anonymous functions, 66, 68 interceptor methods, table of, 58 assigning and passing objects by reference, interfaces, 47 63 introducing dependencies in the name of automated build, 459 good design, 149 call_user_func(), 67 is_callable(), 67–68 callbacks, 66 Java and, 4 502
  2. ■ INDEX late static bindings, 49 initial rise of, in PHP, 11 leaving an overzealous class unchanged, new operator, 16, 21 109 pass-by-reference rather than pass-by-value, magic methods, 62 12–13 making code amenable to variation at PEAR and object-oriented programming, 13 runtime, 146 PHP 3 and, 11 minimizing top-down control and PHP 4 and, 12 dependencies, 100 PHP 5 and, 13 Minion class, 146 PHP 5.3 and namespaces, 14 NastyBoss class, 146–147 PHP 6 and, 14 orthogonality, definition of, 104 properties, setting dynamically, 18 overloading, 58 taking a design-oriented approach to parallel conditionals, 149, 454 projects, 14 PDO class, code listing, 43 __toString(), 16 performing a task in deliberate ignorance of var_dump(), 16 its wider context, 25 Zend Engine (ZE3), 12, 14 phpDocumentor, 459 See also classes polymorphism, 106, 110, 454 ObjectWatcher class, code listing, 292 programming-related web sites, list of, 464 Observable interface, code listing, 204 read(), 102 Observer pattern reading from and writing to configuration attach(), 204–206, 209 files, code example, 102 class diagram, 207 recruit(), 148 detach(), 204–205, 209 reference articles and books, list of, 463 doUpdate(), 206 registerCallback(), 67–68 getStatus(), 206 responsibility and the controlling code, 103 handleLogin(), 203 reusability, promoting, 455 implementing, 204 sale(), 67 Logger class, 203 simplexml_load_file(), 52 Login class, 203–204 Singleton pattern, 149 LoginObserver class, 206 SpreadSheet class, 50 notify(), 204–205 static elements, characteristics of, 43 Observable interface, code listing, 204 static factory method, 49 overview of, 202 static methods, definition of, 42 PEAR and, 332 test frameworks, benefits of, 459 SplObjectStorage class, code listing, 208 $this pseudo-variable, 42 Standard PHP Library (SPL), 208 tight coupling, causes of, 454 update(), 205 __toString(), 65 user access example, code listing, 203 well-designed objects as self-enclosed, 454 onConsecutiveCalls(), 391 write(), 102 operations, 112 See also design patterns OperatorExpression class, 194 object-relational impedance mismatch, 276 operators objects instanceof, 31, 83, 108 casting an object to a string, 16 new, 16, 21 classes and objects, understanding, 15 optional element, 340 definition of, 16 orthogonality identifiers, 16 definition of, 104 503
  3. ■ INDEX orthogonal code, advantages of, 104 prepending package names to class names, output attribute, 448 72 outputAddresses(), 23 using the file system to simulate packages, overloading, 58 76 override attribute, 414 Page Controller pattern, 222 Overview screen, 443 AddVenueController class, code listing, 259 overwrite attribute, 422 advantages and disadvantages of, 261 controller element, 258 error.php, 258 ■P exit(), 258 package command, 341 forward(), 259 package element, 339 include(), 258 @package tag, 351, 353 overview of, 257 package.xml, 327, 435 process(), 259 adding the lib directory to the include path, venues.php, 261 337 view element, 258 api element, 336 PageController class, code listing, 258 channel element, 335 parallel conditionals, 141, 149, 454 contents element, 336 @param tag, 355 dependency elements, table of, 339 parameters, 112 description element, 335 ParamHandler class, 104, 108 description of, 334 parent class, 27 Dialekt package, directory and file structure, 337 parent keyword, 33, 35, 42 dir element, 336 Parser class, code listing, 474 elements of, 334 pattern languages, 125 file element, 336 patternset element file roles, table of, 336 description of, 418 lead element, 335 table of attributes, 419 license element, 336 PDO class, 404 name element, 335 code listing, 43 notes element, 336 getInstance(), 44 package archive (tarball), 336 PEAR, 6, 459 phprelease, list of elements, 340 acquire(), 333 privileges and default role locations, 337 adding the lib directory to the include path, 337 release element, 336 addObserver(), 333 stability element, 336 as element, 341 summary element, 335 browsing repository packages, 323 uri element, 335 channel element, 339 user element, 335 channel-discover command, 328 XML declaration, 334 channel-info command, 328 packages channels, 327 building from scratch versus purchasing, 317 Config class, 330 definition of, 71 Config_Container class, 330 evaluating, 318 Config.php, 330 original versus reusable code, 319 config-get command, 324 PEAR, 318 config-show command, 324 504
  4. ■ INDEX connect(), 138 package command, 341 creating PEAR packages, 334 package element, 339 Data Source Name (DSN), 138 package.xml, 327, 334 dependencies tag, 339 pear command line application, 324 dependency elements, table of, 339 PEAR Foundation Classes, 324 description of, 323 PEAR installer, using, 320 difficulties in managing multiple PEAR_Error class, 52, 331 interdependent packages, 341 PEAR_Exception class, 332 distinguishing between Exception types, PEAR2_SimpleChannelFrontend, managing 332 a channel, 343 downloading and installing a package from PEAR2_SimpleChannelServer, defining a the command line, 327 channel, 342 error handling, 331 pearinstaller element, 339 exclude element, 339 Phing and, 408 file roles, table of, 336 phprelease, list of elements, 340 finding API documentation, 330 phpunit alias, 328 generating archived and compressed PHPUnit package, installing, 328 packages for shipment, 341 PHPUnit, installing, 382 getBacktrace(), table of elements, 331 privileges and default role locations, 337 getCause(), 332–333 process(), 333 getCode(), 331 Pyrus, 324 getErrorClass(), 332 recommended element, 339 getErrorData(), 332 required dependencies, installing, 327 getErrorMethod(), 332 required element, 339 getMessage(), 331 required extensions, 325 handling initial configuration options, 325 root privileges, requirements for, 326 handling project installations with, 407 runing pear install with the -o flag, 327 hosting a channel with a third-party sample list of available packages, 318 provider, 342 setting an error_reporting directive, 330 install element, 341 Unix systems, 324 installconditions element, 341 uri element, 339 installing packages with the install using PEAR packages, 329 command, 326 using Pyrus channel management to serve isError(), 331 PEAR packages, 342 Linux systems, 324 using the naming convention common to Log package, installing, 326 PEAR packages, 78 managing packages, 344 wget command, 327 max element, 339 XML_Feed_Parser package, 332 MDB2 package, 138 See also PHP MDB2_Driver_Common class, 138 pear package command, 448 migrating to, 325 PEAR_Exception class, 332 min element, 339 pearinstaller element, 339 MyConfig class, code example, 330 performOperations(), 293 notifyError(), 333 Perl, 11 object-oriented programming and, 13 persistence classes, illustration of, 312 Observer pattern, 332 PersistenceFactory class, illustration of, 301 optional element, 340 Phing, 7, 439, 459 505
  5. ■ INDEX acquiring and installing, 408 properties, setting on the command line, adding a dependency to a build file, 410 414 Ant, 407 propertyName attribute, 424 begintoken attribute, 420 replacetokens element, 420 build.xml, 407, 409 ReplaceTokens filter, 420 building up include and exclude rules, 417 setpass target, 424 clean argument, 425 srclib fileset element, 422 commenting build files, 409 StripPhpComments task, 419 composing the build document, 408 target element, table of attributes, 414 copy element, table of attributes, 422 targets, setting up dependencies, 410 Copy task, 420, 422 tasks, definition of, 421 -D flag, 413 unless attribute, 412–413 defaultValue attribute, 424 uses for, 408 delete element, 425 using make as a build solution, 407 deleting a build directory, 425 -v flag, 408 description attribute, 411 ways of setting a property, 416 description of, 407 when a property isn’t found, 415 dir attribute, 417 XML declaration, including, 409 echo element, 423 PHP Echo task, 421 Atkinson, Leon, 5 endtoken attribute, 420 Fuecks, Harry, 5 ensuring that properties are populated, 416 Gutmans, Andi, 5, 11 env prefix in a property reference, 415 hinted return types, 156 excludes attribute, 417 Lerdorf, Rasmus, 5, 11 file attribute, 422 namespaces and, 455 FileSet data type, 417 origins of, 4 fileset element, table of attributes, 417 pass-by-reference rather than pass-by-value, filterchain element, 419–420 12–13 filters, 419 PEAR, 6, 13 id attribute, 417 Phing, description of, 407 if attribute, 412–413 PHP 3 and objects, 11 includes attribute, 417 PHP 4 and objects, 12 input element, table of attributes, 424 PHP 4 and var keyword, 17, 35 installing applications, 320 PHP 5 and objects, 13 main task, 413 PHP 5, release features, 453 override attribute, 414 PHP 5.3 and namespaces, 14, 71 overriding the project element’s default PHP 6 and objects, 14 attribute, 410 PHP as a loosely typed language, 22 overwrite attribute, 422 PHP/FI 2.0, 11 patternset element, table of attributes, 419 procedural programming and, 14 PEAR and, 408 projects turning into design disasters, 3 phing command, 408 Suraski, Zeev, 5, 11, 13 project element, 409 taking a design-oriented approach to -projecthelp flag, 411 projects, 14 promptChar attribute, 424 Unicode string handling, 14 properties, built-in, 415 Zend Engine (ZE3), 12, 14 properties, declaring, 412 Zend Engine 2, 5, 453 506
  6. ■ INDEX See also PEAR amending the config.xml and build.xml PHP_CodeBrowser files, 442 installing and using, 433 bug in the phpuc graph command, 442 phpcb command line tool, 434 project command, using, 441 PHP_CodeSniffer, 433 phpUnderControl php.ini, 79, 337 amending the CruiseControl environment phpdoc command, 349 to support phpUnderControl, 439 PHPDocumentor, 7, 321, 431, 459 ezcGraph, installing, 438 adding comments to source code, 350 installing, 438 @author tag, 352 PHPUnit, 7, 430 Beaver, Greg, 353 addUser(), 385 class relationships, viewing, 350 AddVenueTest class, code listing, 397 classes, documenting, 352 assertEquals(), 384 @copyright tag, 352 assertions, definition of, 383 creating hyperlinks in documentation, 356 assertions, support for, 384 -d flag, 349 AssertThat(), 387 -dn flag, 349 AssertTrue(), 386 DocBlock comments, 350, 352 behavior verification, 389 documentation, generating, 349 Bergmann, Sebastian, 382 documenting methods, 355 brittle nature of many test harnesses, 404 documenting private elements, 354 centralizing test fixtures into Object Mothers, 405 documenting properties, 353 checking the behavior of the UserStore class downloading and installing, 348 when an operation fails, 385 file-level documentation, providing, 353 combining real and mocked components in -h flag, 348 testing, 405 @license tag, 353 constraints, 386 @link tag, 358 creating a minimal test case class, 382 making a reciprocal link, 358 creating a test method, 383 namespaces and, 353 creating a Web UI superclass, 398 navigating and examing packages, 351 DBFace class, 404 output menu, sample page, 349 debugging tests, 404 @package tag, 351, 353 expects(), 389–390 @param tag, 355 exporting a Selenium test as a PHPUnit phpdoc command, 349 class, 402 -pp flag, 354 fail(), 385 @return tag, 355 faking the context of the class you are running as a command line tool, 349 testing, 389 @see tag, 356 fixture, definition of, 383 SourceForge.net, 348 fluent interface, 389–390 -t flag, 349 getMock(), 389 tags, defining, 351 getUser(), 393 -ti flag, 349 handleRequest(), 395 @uses tag, 358 installing using PEAR, 382 @var tag, 353 is_array(), 393 See also documentation matcher methods, table of, 390 phprelease, list of elements, 340 method(), 390 phpuc command line tool, 438 mock objects, generating, 389 507
  7. ■ INDEX notifyPasswordFailure(), 389 table of assertion methods, 384 onConsecutiveCalls(), 391 table of some constraint methods, 387 overview of, 382 PhpWiki, 460 PDO, 404 Pollution class, 182 PHPUnit_Framework_Constraint objects, polymorphism, 454 386 code examples, 106 PHPUnit_Framework_TestCase class, table conditional statements and, 107, 110 of assertion methods, 384 definition of, 106 PHPUnit_Framework_TestCase class, table parallel conditional statements and, 141 of some constraint methods, 387 Portland Pattern Repository, 126 PHPUnit_Framework_TestSuite class, 431 Preferences class placing test classes in a test directory, 386 code listing, 150 refactoring a web application for testing, getInstance(), 151 394 mediating object instantiation, 150 regression testing, definition of, 394 Preferences object, instantiating, 151 RequestRegistry class, 396 requirements of, 149 returnValue(), 391 prepareStatement(), 267 run(), 395 presentation layer, 223, 291 runCommand(), 397 Application Controller pattern, 245 Runner.php, 394 Front Controller pattern, 235 running test suites, 385 Page Controller pattern, 257 Selenium IDE control panel, 399 Template View pattern, 262 setExpectedException(), 385 View Helper pattern, 262 setting up a library of complex constraints, 387 view, definition of, 235 setUp(), 382–383, 388 See also business logic layer stubs, definition of, 389 primitive types tearDown(), 383, 388 checking the type of a variable, 23 test case classes, naming, 382 definition of, 22 test methods, naming, 383 outputAddresses(), 23 testGetUser(), 383 PHP as a loosely typed language, 22 testing at the system level and class level, primitive types and test functions, table of, 403 22 testing for failure, 384 strategies for dealing with argument types, 25 testing that an exception is thrown, 385 type-related errors, preventing, 25 User class, code listing, 392 print_r(), 84, 89, 279 UserStoreTest class, 382 private keyword, 17 ValidateTest class, code listing, 385 procedural programming validateUser(), 385, 393 cohesion, definition of, 104 will(), 390 comparing to object-oriented design, 100, with(), 390 103 writing web tests, 394 coupling in, 104 xUnit, 382 orthogonality, definition of, 104 See also errors; testing reading from and writing to configuration phpunit alias, 328 files, code example, 100 PHPUnit_Framework_Constraint objects, 386 readParams(), 100, 103 PHPUnit_Framework_TestCase class, 382 responsibility and the controlling code, 103 508
  8. ■ INDEX writeParams(), 100, 103 See also object-oriented design ■Q Question classes, code listing, 200 process(), 184, 219, 259, 333 ProcessRequest class, 180, 183 project element, table of attributes, 409 ■R promptChar attribute, 424 RapidSVN, 362 properties read(), 102 access property variables, 18 Reader interface, code listing, 473 accessing methods and properties in the readParams(), 100, 103 context of a class, 41 recommended element, 339 accessing properties using inheritance, 33 recruit(), 148 assigning values to, 18 recursive descent parser, 124 defining constant properties within a class, refactoring, 5 44 Reflection API definition of, 17 argData(), 93 documenting in phpDocumentor, 353 array_slice(), 91 get_class_vars(), 85 classData(), 90 setting dynamically, 18 definition of, 87 setting to private or protected, 36 examining a class, 90 static properties, 43 examining a method, 91 var keyword, 17, 35 examining method arguments, 93 propertyName attribute, 424 execute(), 95 protected keyword, 17 export(), 88 Prototype pattern file(), 91 Civilization-style game, code listing, 163 getClass(), 93, 96 composition and, 164 getClassSource(), 91 public keyword, 17 getEndLine(), 91, 93 publishers element, 446, 449 getFileName(), 91, 93 push(), 476 getMethod(), 91, 93 Pyrus getMethods(), 91, 96 config-show command, 325 getName(), 90, 93 creating and hosting channels, 342 getParameters(), 93 downloading the phar package, 324 getStartLine(), 91, 93 hosting a channel with a third-party handleMethod(), 96 provider, 342 init(), 95, 97 installing, 324 invoke(), 96 Log package, installing, 326 isAbstract(), 90 managing packages, 344 isInstantiable(), 90 PEAR2_SimpleChannelFrontend, managing isPassedByReference(), 94 a channel, 343 isSubclassOf(), 95 PEAR2_SimpleChannelServer, defining a isUserDefined(), 90 channel, 342 methodData(), 92 required and optional dependencies, Module interface, code listing, 94 installing, 327 ModuleRunner class, 95 using Pyrus channel management to serve PEAR packages, 342 newInstance(), 96 partial table of classes, 87 Reflection class, 88 509
  9. ■ INDEX ReflectionClass class, 88, 90–91, 95 Request class, 259 ReflectionExtension class, 87 code listing, 242 ReflectionFunction class, 87 RequestRegistry class, 259, 396 ReflectionMethod class, 91, 93 code listing, 230 ReflectionParameter class, 93 require_once(), 76, 82 ReflectionUtil class, 91 require(), 76, 79, 82 returnsReference(), 92 required element, 339 setPerson(), 95 resolve command, 370 uses for, 87 @return tag, 355 using, 94 return type hinting, 453 registerCallback(), 67, 68 returnsReference(), 92 RegistrationMgr class, 140 returnValue(), 391 Registry class, 218, 278 reusability, promoting, 455 Registry pattern, 222 Rice, David, 291 application scope, 229 rule of three, 127 ApplicationHelper class, 225 run(), 237, 395 ApplicationRegistry class, code listing, 232 runCommand(), 397 getRequest(), 227 Runner.php, 394 Hunt, David, 226 implementing, 226 implementing Registry classes for different ■S sale(), 67 scopes, 229 scan(), 476–478 instance(), 228 Scanner class, code listing, 467 managing serialization, 234 ScannerState class, 472 MemApplicationRegistry class, code listing, scope 233 application scope, 229 overview of, 225 definition of, 17, 229 Registry class, code listing, 226 implementing Registry classes for different registry, definition of, 226 scopes, 229 RequestRegistry class, code listing, 230 three levels of, 229 scope, definition of, 229 @see tag, 356 session_start(), 232 selectAllStmt(), 286 SessionRegistry class, code listing, 231 Selection Factory pattern __sleep(), 234 buildWhere(), 310 Thomas, David, 226 getComps(), 310 using Registry objects as factories and in illustration of, 308 testing, 228 implementing, 307 variables as having session scope, 229 newSelection(), 310 __wakeup(), 234 SelectionFactory class, code listing, 310 regression testing, definition of, 394 selectStmt(), 279, 286 relative namespaces, 74 Selenium release element, 336 description of, 398 remove command, 372–373 exporting a test as a PHPUnit class, 402 removeUnit(), 173, 176 online documentation for, 403 replace(), 193 Selenium IDE and Selenium RC, replacetokens element, 420 downloading and installing, 398 ReplaceTokens filter, 420 Selenium IDE control panel, 399 510
  10. ■ INDEX testing to verify text on a web page, 400 Standard PHP Library (SPL), 208 self keyword, 42, 49 static factory method, 49 sequence diagrams, 117 static keyword, 41, 50 SequenceParse class, code listing, 477 static methods, 102 session_start(), 232 accessing static properties, 42 SessionRegistry class, 231, 234 definition of, 42 __set(), 59 static properties, availability of, 43 set_include_path(), 79 status command, 369 setDepth(), 211 status element, 249 setExpectedException(), 385 statuses(), 255 setHandler(), 476, 485 stereotypes, 111 setpass target, 424 Strategy pattern, 135 setPerson(), 95 defining subclasses, 198 setSpaces(), 285, 287 implementing, 199 setState(), 472, 478 mark(), 199 setUp(), 382–383, 388 Marker objects, code listing, 200 setValue(), 194 MarkLogicMarker class, 202 ShopProduct class overview of, 198 getInstance(), 43 Question classes, code listing, 200 products table, defining, 43 reducing subclassing and increasing ShopProductWriter class flexibility, 199 redefining, 45 repeating an algorithm across siblings in an write(), 45 inheritance tree, 199 SimpleXML, 24, 249 StringReader class, code listing, 473 simplexml_load_file(), 52 strings Singleton pattern, 225 casting an object to a string, 16 comparing to global variables, 152 __toString(), 16 dependencies created by, 152 StripPhpComments task, 419 deploying sparingly, 152 StructureRequest class, 180 mediating object instantiation, 150 stubs, 224, 389 overview of, 149 Subversion, 7, 430 Preferences class, code listing, 150 accessing a project within the repository, 364 Preferences object, instantiating, 151 accessing the repository from a remote summary of, 152 machine using SSH, 364 __sleep(), 234 acquiring a snapshot, 374 Smarty, 235 add command, 371–372 snapshot branches, 365 adding a project to the repository, 364 SourceForge.net, 348 allowing users full access to the repository, SpaceMapper class, 291 364 SplObjectStorage class, code listing, 208 beginning a project, 364 SpreadSheet class, 50 benefits of, 319 SQLite, 404 Berkeley DB, 363 srclib fileset element, 422 branches, 365, 459 ssh-agent, 364 checking out a project from the repository ssh-keygen, 364 after importing it, 367 stability element, 336 checking out versions of the codebase based Stahnke, Michael, 364 on a date or a label, 362 511
  11. ■ INDEX checking whether Subversion is already sample output after importing, 366 installed, 362 snapshot branches, saving, 365 checkout command, 374 specifying files and patterns to ignore configuration file, editing, 365 during import, commit, and update, 365 conflicts, identifying and handling, 370 ssh-agent, 364 coordinating the codebase through a ssh-keygen, 364 central repository, 361 Stahnke, Michael, 364 copy command, 373 status command, 369 create command, 363 Subversion URL, format of, 364 creating a new group (svnusers), 363 svn directory, 363, 367 creating a repository, 363 svn network protocol, 364 directories, adding and removing, 372–373 svnadmin command, 363 dollar sign as the command prompt, 362, tags directory, 365 367 TortoiseSVN, 363 downloading, 362 trunk, 365, 367 editor, configuring, 366 typical conventions for version errors when importing, 366 management, 365 explicitly committing a changed file, 370 update command, 368 export command, 374 updating files and committing changes, 368, files, adding and removing, 371–372 371 freezing a moment in a project’s usermod command, 363 development, 373 WebDav protocol, 364 generating a clean release version of the working with a graphical user interface codebase, 374 instead of the command line, 362 generating a project version without See also version control Subversion metadata, 373 summary element, 335 groupadd command, 363 SUnit, 382 handling version control, 319 superclass, 27 import command, 365 Suraski, Zeev, 5, 11, 13 importing a project directory, 364 svn directory, 363, 367 list (ls) command, 364 svn network protocol, 364 maintaining parallel strands of project svnadmin command, 363 development, 362, 374 making user authentication easier, 364 managing multiple versions of a project, 365 ■T merge command, 377 tags, defining in phpDocumentor, 351 overriding the repository version of a file, tags directory, 365 370 targetClass(), 283, 291 project, branching, 374 targets project, exporting, 374 definition of, 410 project, tagging, 373 setting up dependencies among, 410 RapidSVN, 362 tasks remove command, 372–373 Copy task, 420, 422 removing temporary items, 365 definition of, 421 resolve command, 370 Echo task, 421 resolving conflicting files, 370 main task, 413 rolling back by date or tag to any moment, StripPhpComments task, 419 459 TaxCollectionVisitor class, 215 512
  12. ■ INDEX tearDown(), 383, 388 TextNotifier class, 140 Template Method pattern, 195 $this pseudo-variable, 20, 42 Template View pattern, 222 Thomas, David, 5, 104, 226 advantages and disadvantages of, 264 ThoughtWorks, 436 allowing views to manage presentation throw keyword, 53 only, 262 throwing an exception, 53 overview of, 262 tight coupling, causes of, 454 term(), 476, 478 Tile class, 179 terminal parsers, 476 $tile property, 182 testGetUser(), 383 TileDecorator class, 182 testing token(), 473 acceptance tests, 379 tokens, 467 addUser(), 381 TortoiseSVN, 363 automated testing, 7 __toString(), 16, 65 Beck, Kent, 5, 382 totalize(), 57 benefits of, 405 Transaction Script pattern, 222 brittle nature of many test harnesses, 404 addVenue(), 268 combining real and mocked components in advantages and disadvantages of, 269 testing, 405 Base class, code listing, 266 Continuous Integration (CI), 322 doStatement(), 267–268 debugging tests, 404 execute(), 268 eliminating errors using a test harness, 322 implementing, 265 functional tests, 379 overview of, 265 Gamma, Erich, 5 prepareStatement(), 267 getUser(), 381 VenueManager class, code listing, 267 introducing errors by changing a trigger(), 477–478 component’s context, 321 trunk, 365, 367 JUnit, 5, 382 try clause, 54 maintaining a test harness, 380 PHPUnit, 382 running test suites, 385 ■U running tests from the command line, 380 Unicode, 14 SUnit, 382 Unified Modeling Language (UML), 6 test cases, 379 abstract classes, representing, 111 testing at the system level and class level, aggregation, 114 403 associations, unidirectional and testing by hand, 380 bidirectional, 113 testing every component regularly, 379 attributes, 111 testing for failure, 384 class diagrams, 110 testing that an exception is thrown, 385 composition, 115 unit tests, 379 constraints, 111 UserStore class, code listing, 380, 391 Fowler, Martin, 110 validateUser(), 381 inheritance relationships, describing, 112 Validator class, code listing, 381 interfaces, representing, 111 xUnit, 382 object lifelines, 117 See also errors; PHPUnit operations, 112 Tests tab, 446 parameters, 112 513
  13. ■ INDEX sequence diagrams, 117 use keyword, 74 stereotypes, 111 use relationships, 115 use relationships, describing, 115 User class, code listing, 392 using notes for clarification, 116 user element, 335 visibility symbols in UML, table of, 112 usermod command, 363 See also object-oriented design UserStore class, code listing, 380, 391 Unit class, 170, 210 UserStoreTest class, 382 Unit of Work pattern @uses tag, 358 addClean(), 293 usessl element, 447 addDirty(), 293 addNew(), 293, 295 ■V collection(), 294 ValidateTest class, code listing, 385 defining objects as dirty, 293 validateUser(), 381, 385, 393, 446 Domain class, 294 Validator class, code listing, 381 DomainObject class, code listing, 293 var keyword, 17, 35 finder(), 294 @var tag, 353 getCollection(), 294 var_dump(), 16, 89 getFinder(), 294 variable(), 485 implementing, 292 VariableExpression class, code listing, 193 Mapper class, 295 VariableHandler class, 485 markClean(), 295 Venue class, code listing, 271, 284 markDirty(), 295 VenueCollection class, 282 marking a dirty object as clean, 293 VenueManager class, code listing, 267 markNew(), 294 VenueMapper class, code listing, 278 ObjectWatcher class, code listing, 292 VenueObjectFactory class, 299 performOperations(), 293 venues.php, 261 Rice, David, 291 version control saving only those objects that need saving, benefits of, 459 291 checking out versions of the codebase based testing for modified objects, 296 on a date or a label, 362 unit tests coordinating the codebase through a definition of, 379 central repository, 361 goals of, 380 Git, 362 $units property, 171, 173 maintaining parallel strands of project unless attribute, 412–413 development, 362 unqualified name, 73 Mercurial, 362 __unset(), 60 Subversion, 319 update command, 368 using on a multi-developer project, 319 Update Factory pattern See also Subversion buildStatement(), 309 view, definition of, 235 illustration of, 308 view element, 248 implementing, 307 View Helper pattern newUpdate(), 309–310 advantages and disadvantages of, 264 UpdateFactory class, code listing, 308 allowing views to manage presentation update(), 205, 279 only, 262 uri element, 335, 339 overview of, 262 use clause, 69 514
  14. ■ INDEX using the View Helper class and the Request will(), 390 object, code listing, 263 with(), 390 view layer, 222 Woo system, description of, 224 visibility keywords, 36 write(), 102 definition of, 17 writeParams(), 100, 103 using in a method declaration, 19 wrong element, 448 visibility symbols and UML, 112 visit(), 212 visitArmy(), 213 ■X Xdebug, 432 Visitor pattern Xinc, 436 class diagram, 215 XML Log File link, 449 implementing, 211 XML_Feed_Parser package, 332 overview of, 210 XmlException class, 55 summary of, 215 xUnit, 7, 382 Vlissides, John, 125 ■W ■Z Zend Engine (ZE3), 12, 14 __wakeup(), 234 Zend Engine 2, 5, 453 WebDav protocol, 364 wget command, 327 wikis DokuWiki, 460 Foswiki, 460 PhpWiki, 460 515
  15. ■ INDEX 516
Đồng bộ tài khoản