Cherrycake
ExamplesGithub
version 2.x alpha
version 2.x alpha
  • Introduction
  • Status
  • Changelog
  • Migration
  • Architecture
    • Basics
    • Modules
    • Classes
    • Lifecycle
      • Deep lifecycle
    • Performance
    • Security
    • Patterns
      • Files structure
    • Items
    • Server requirements
  • Guide
    • Getting started
      • Skeleton start
      • Docker start
    • Modules guide
    • Classes guide
    • Actions guide
      • Complex actions
      • Variable path components
      • Accept GET or POST parameters
      • Getting the URL of an action
      • Cached actions
      • Brute force attacks
    • Patterns guide
      • Passing variables to a pattern
      • Nested patterns
      • Cached patterns
    • Cache guide
      • Time To Live
      • Using cache
      • Lists
      • Queues
      • Pools
    • Database guide
      • Basic queries
      • Prepared queries
      • Cached queries
      • Cache key naming
      • Removing queries from cache
    • Items guide
      • Item cache
      • Item lists
      • Items custom filters
      • Items custom ordering
      • Mixing filters and ordering
      • Items with relationships
      • Items cache
    • HtmlDocument guide
    • Css and Javascript guide
      • Modules injecting CSS and JavaScript
    • Session guide
    • Login guide
      • Creating a complete login workflow
    • Locale guide
      • Multilingual texts
      • Domain based site localization
    • Log guide
      • Loading Log events from the database
    • Stats guide
      • Stats events with additional dimensions
      • Loading Stats events from the database
    • Janitor guide
      • Janitor tasks configuration files
    • Command line interface
    • Debugging
  • Reference
    • Core modules
      • Actions
        • Actions methods
      • Browser
      • Cache
        • Cache methods
      • Css
        • Css methods
      • Database
      • Email
      • Errors
      • HtmlDocument
        • HtmlDocument methods
      • ItemAdmin
      • Janitor
        • Janitor methods
      • Javascript
        • Javascript methods
      • Locale
        • Locale methods
      • Log
        • Log methods
      • Login
        • Login methods
      • Output
        • Output methods
      • Patterns
        • Patterns methods
      • Security
        • Security methods
      • Session
        • Session methods
      • Stats
        • Stats methods
      • SystemLog
      • TableAdmin
      • Translation
      • Validate
    • Core classes
      • Action
        • Action methods
        • Action properties
      • AjaxResponseJson
      • BasicObject
        • BasicObject methods
      • CacheProvider
        • CacheProvider methods
      • Color
      • DatabaseProvider
        • DatabaseProvider methods
      • DatabaseResult
        • DatabaseResult methods
        • DatabaseResult properties
      • DatabaseRow
      • Engine
        • Engine methods
        • Engine properties
      • Gradient
      • Item
        • Item methods
        • Item properties
      • Items
        • Items methods
        • Items properties
      • Image
      • JanitorTask
        • JanitorTask methods
        • JanitorTask properties
      • LogEvent
        • LogEvent methods
        • LogEvent Properties
      • LogEvents
        • LogEvents methods
      • Module
        • Module methods
        • Module properties
      • Response
      • Request
        • Request methods
      • RequestParameter
        • RequestParameter methods
      • RequestPathComponent
        • RequestPathComponent methods
      • Result
      • StatsEvent
        • StatsEvent properties
      • StatsEvents
        • StatsEvents methods
      • SystemLogEvent
        • SystemLogEvent methods
        • SystemLogEvent properties
      • SystemLogEvents
        • SystemLogEvents methods
  • Code conventions
  • License
  • Extras
Powered by GitBook
On this page
  • Entities
  • File naming
  • Code structure

Was this helpful?

Code conventions

This are the official programming standards Cherrycake follows.

PreviousSystemLogEvents methodsNextLicense

Last updated 5 years ago

Was this helpful?

Cherrycake uses the for entity naming, file naming and code structure. Of course, you can use your favorite conventions in your Cherrycake app.

Entities

  • camelCase for variables, properties and methods.

  • PascalCase for types, classes and modules.

  • UPPER_CASE_SNAKE_CASE for constants.

For example:

define("DEFINE_NAME", true);

$variableName = null;

class ClassName {
    var $propertyName;
    function methodName() {
        [...]
    }
}

$objectName = new ClassName;

File naming

Please note that class auto-loading might not work properly if you don't follow this naming conventions.

Code structure

Feel free to use the structure methodology you prefer in your code. Cherrycake's own choice is tabs instead of spaces and a somewhat typical multi-line approach to function declarations and overall tidiness.

Here's an example code with some of this conventions in place:

<?php // Use the full PHP opening tag instead of the shorthand <? for compatibility

class ClassName { // Brackets on the same line
    var $propertyName = 1 + 3; // Operators surrounded by spaces
    // Empty lines between logical blocks are acceptable to add readability
    /**
     * PHPDoc is used to document code when needed.
     * @param boolean $divisor The divisor.
     * @return boolean True on success, false on failure.
     */
    function methodName($divisor) { // No separation between the method/function name and the parenthesis
        global $e; // The Cherrycake engine is stored globally in the $e variable

        if ($this->propertyName > 100) // Control structures like if, for, while and switch are one space away from the parenthesis
            return false; // Single-line statements without brackets are acceptable, as long as they improve readability
                
        for ($i = 1; $i < 100; $i ++) // Space after semicolons in for control structures
            if ($i % $divisor == 0) // Nested control structures without brackets are acceptable, as long as they improve readability
                echo "$i is divisible by $divisor"; // Variable interpolation in strings is acceptable when it adds readability
        
        $e->ModuleName->methodName(
            $this->propertyName, // Multiline tabbed parameters are acceptable to add readability when the number of parameters is long
            [
                "id" => $this->propertyName,
                "key" => [
                    "a" => true, // Depth of multidimensional arrays is also expressed with tabs
                    "b" => 12
                ]
            ] // Specially when functions receive complex parameters like this hash array
        );
        
        return true;
    }
}

// No need to use the ?> PHP closing tag

If you're contributing to the Cherrycake Engine, please follow this conventions.

Class names, module names and directories follow the same PascalCase convention, take a look at the section for more information.

JavaScript conventions
Files structure