pear:rfc:pear2_standards
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
pear:rfc:pear2_standards [2009/09/16 21:42] – add note about the package naming RFC ashnazg | pear:rfc:pear2_standards [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 6: | Line 6: | ||
* Title: PEAR2 Coding Standards | * Title: PEAR2 Coding Standards | ||
- | * Version: | + | * Version: |
* Status: | * Status: | ||
* Type: Standards | * Type: Standards | ||
- | * Last updated: September | + | * Last updated: September |
==== Author(s) Information ==== | ==== Author(s) Information ==== | ||
Line 166: | Line 166: | ||
<? | <? | ||
- | if (!class_exists(" | + | if (!class_exists(" |
throw new \PEAR2\PackageName\Exception(' | throw new \PEAR2\PackageName\Exception(' | ||
', | ', | ||
Line 210: | Line 210: | ||
==== Class Naming convention ==== | ==== Class Naming convention ==== | ||
- | A class naming rule may potentially be added to these standards, if the [[pear/ | ||
- | ==== Package Naming convention ==== | + | The naming |
- | A package | + | * Start with capital letter, e.g. class Foo {} |
+ | * CamelCase for multi-worded class names, e.g. class FooBarBaz {} | ||
+ | * Abbreviations only start with capital letter, e.g. class MrClean {} | ||
+ | * Acronyms should be fully capitalized, | ||
+ | * syntax/ | ||
+ | * the suffix should be a full legible word, not a cryptic letter/abbreviation (e.g. FooAbst, FooA) | ||
+ | * a suffix for an Abstract or Interface class name is *required* | ||
- | ==== Base Exception class ==== | + | The only exception to the Interface suffix requirement |
- | PEAR2\Exception | + | |
- | <? | ||
- | | ||
- | class Exception extends \PEAR2\Exception {} | ||
- | ?> | ||
- | PEAR2\Exception | + | === Examples === |
+ | Here are some real-life examples gleaned from PEAR1 packages: | ||
+ | * "class Text_Diff" | ||
+ | * "class DB_DataObject" | ||
+ | * "class Auth_PrefManager" | ||
+ | * "class Services_Amazon_SQS" | ||
+ | * " | ||
+ | * " | ||
+ | |||
+ | |||
+ | === Requirement === | ||
+ | The only exception to this rule is the Base Package Exception Interface, which is specifically required to be named " | ||
+ | |||
+ | |||
+ | |||
+ | ==== Base Exception interface ==== | ||
+ | |||
+ | Each package must define a base Exception interface which is implemented by any exception thrown within the package. | ||
+ | |||
+ | **PEAR2/ | ||
+ | <code php> | ||
+ | <? | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | |||
+ | SPL exceptions are encouraged, and should | ||
+ | |||
+ | Extending SPL Example: | ||
+ | **PEAR2/ | ||
+ | <code php> | ||
+ | <? | ||
+ | | ||
+ | class UnexpectedValueException extends \UnexpectedValueException implements Exception {} | ||
+ | </ | ||
+ | |||
+ | |||
+ | Exception throwing example: | ||
+ | <code php> | ||
+ | <? | ||
+ | | ||
+ | class Foo | ||
+ | { | ||
+ | | ||
+ | { | ||
+ | | ||
+ | case ' | ||
+ | case ' | ||
+ | case ' | ||
+ | | ||
+ | | ||
+ | | ||
+ | throw new UnexpectedValueException($method . ' is not a valid method.' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | User exception catching example: | ||
+ | <code php> | ||
+ | <? | ||
+ | | ||
+ | try { | ||
+ | $p = new \PEAR2\PackageName\Foo(); | ||
+ | | ||
+ | } catch (\PEAR2\PackageName\Exception $e) { | ||
+ | echo " | ||
+ | } | ||
+ | </ | ||
=== Requirement === | === Requirement === | ||
No Exceptions to this rule | No Exceptions to this rule | ||
- | === Potential Alteration === | ||
- | This rule could potentially be altered by the [[pear/ | ||
==== Data files ==== | ==== Data files ==== | ||
Line 242: | Line 311: | ||
... | ... | ||
// retrieve data from info.txt | // retrieve data from info.txt | ||
- | $info = file_get_contents(dirname(__FILE__) . ' | + | $info = file_get_contents(dirname(__FILE__) . '/../ |
?> | ?> | ||
pear/rfc/pear2_standards.1253137374.txt.gz · Last modified: 2017/09/22 13:28 (external edit)