SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,135
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)

    Assistance Organizing Library Files

    What is the best way to organize files any tips, techniques, principles?

    I'm asking because the time has come to organize the library I've been working on, but I would like to do this in the most meaningful manor. Currently all these files are in the same directory so before I make any of these changes I would like to have a solid way to organize everything mapped.

    What I've attempted to do here is organize them based on a module concept. For example, the select directory would contain most the files that belong to that functionality. This seems like a good way to this. What do you think?

    thanks

    inflector
    ----------------------------------------------------------------
    - inflector/
    -- inflector.class.php
    ----------------------------------------------------------------

    list
    ----------------------------------------------------------------
    - list/
    -- active_record_list.interface.php
    ----------------------------------------------------------------

    node
    ----------------------------------------------------------------
    - node/
    -- active_record_node.interface.php
    ----------------------------------------------------------------

    xml
    ----------------------------------------------------------------
    - xml/
    -- active_record_dom_element.class.php
    -- active_record_xml.interface.php
    ----------------------------------------------------------------

    data_entity
    ----------------------------------------------------------------
    - data_entity/
    -- active_record_data_entity.interface.php
    -- active_record_data_entity.class.php
    -- iterator/
    --- active_record_data_entity_iterator.class.php
    ----------------------------------------------------------------

    migration
    ----------------------------------------------------------------
    - migration/
    --- active_record_migrate.class.php
    ----------------------------------------------------------------

    generation
    ----------------------------------------------------------------
    - generation/
    --- active_record_generate.class.php
    ----------------------------------------------------------------

    active_record
    ----------------------------------------------------------------
    - active_record/
    -- collection/
    --- active_record_collection.class.php
    --- iterator/
    ---- active_record_basic_iterator.class.php
    -- record/
    --- active_record.class.php
    ----------------------------------------------------------------

    save
    ----------------------------------------------------------------
    save/
    -- active_record_savable.interface.php
    -- active_record_save.class.php
    -- list/
    --- active_record_insert.class.php
    --- active_record_update.class.php
    -- statement/
    --- active_record_insert_statement.class.php
    ----------------------------------------------------------------

    model
    ----------------------------------------------------------------
    -- model/
    --- config/
    ---- active_record_model_config.class.php
    ---- active_record_dynamic_model.class.php
    ---- active_record_model_config.interface.php
    ----------------------------------------------------------------

    cascade
    ----------------------------------------------------------------
    - cascade/
    -- active_record_cascade.class.php
    -- action/
    --- active_record_cascade_action.interface.php
    --- active_record_delete.class.php
    --- active_record_deleteable.interface.php
    --- active_record_deactivate.class.php
    -- node/
    --- active_record_cascade_node.class.php
    ----------------------------------------------------------------

    select
    ----------------------------------------------------------------
    - select/
    -- collect/
    --- active_record_collection_agent.class.php
    -- find/
    --- config/
    ----- active_record_find_config.class.php
    ----- active_record_find_config.interface.php
    -- statement/
    --- active_record_select_node.class.php
    --- active_record_count.class.php
    --- active_record_select.class.php
    -- clause/
    --- active_record_select_clause.class.php
    --- active_record_where_clause.class.php
    --- active_record_sort_clause.class.php
    --- active_record_limit_clause.class.php
    --- active_record_group_clause.class.php
    --- active_record_having_clause.class.php
    ----------------------------------------------------------------

    validation
    ----------------------------------------------------------------
    - validation/
    -- active_record_validation.class.php
    -- active_record_null_validation.class.php
    -- active_record_validation.interface.php
    ----------------------------------------------------------------

    query
    ----------------------------------------------------------------
    - query/
    -- active_record_query.class.php
    -- action/
    --- active_record_query_action.interface.php
    ---- actions/
    ----- active_record_set_primary_key_action.class.php
    ----- active_record_cast_action.class.php
    ----------------------------------------------------------------

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,135
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    I'm more or less looking for information regarding the organization of a library not a site/application.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,135
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    After a long and strenuous process this is where I'm at in terms of organizing all these files in a meaningful and self describing way:

    Code:
    pkg: active_record
    
    ***********************************
    *********** select  ***************
    
    - count_statement
    - select_statement
    - select_node
    - collection_agent
    
    - clause/
    
    	- select_clause
    	- where_clause
    	- group_clause
    	- having_clause
    	- sort_clause
    	- limit_clause
    
    - find/
    
    	- find_config
    
    ***********************************
    ************* save  ***************
    
    - save
    
    - insert/
    
       - insert
       - insert_statement
       
    - update/
    
       - update
       
    **********************************
    *********** cascade  **************
    
    - cascade
    - cascade_node
    
    - action/
    	
       - deactivate
       - delete
       
    ************************************
    ************* rake  ***************
    
    - rake 
    - generate
    
    ***********************************
    ********** storage  ***************
    
    - active_record
       
    - entity/
       
       	- data_entity
      	- data_entity_iterator
          
    - collection/
          
        - collection
      	- collection_iterator    
      	
    ***********************************
    ************ core  ****************
    
    - install
    
    	- inflector/
       
          - inflector      
          
       - model/
       
     	  - model_config
    	  - dynamic_model_config
    	  
       - query/
       
          - query.class.php
          
          - action/
          
             -- cast_action
             -- set_primary_key
    	 
    ***********************************
    ************ interface ************
    
    - list
    - validation
    - node
    - deleteable
    - dumpable
    - savable
    - xml
    - find_config
    - model_config
    - data_entity
    - cascade_action
    
    ***********************************
    I think its much more organized then the previous hierarchy.

    What is the opinion on places all interfaces in one place? – is that a bad or good idea in general?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Location
    Norway
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about the Zend way of doing it?
    At work we use something like the way Zend does it.

    That is;
    - If you have a class Zend_Form_Element_Text, the path to the file containing this class would be Zend/Form/Element/Text.php.
    - When autoloading, you can just replace the "_" in the classname with "/" and add a ".php" extention and then you have the path for the class.
    - In the library folder you can put an autoload.php which is a file containing an autoload function which you can register with the spl_autoload_register.

    Then, when you need to use the library, just include the autoload file and start using the classes..

    Example layout:
    lib/
    -autoload.php
    -Oddz/
    --Form.php
    --Form/
    ---Element.abstract.php
    ---Element/
    ----Text.php
    ----TextArea.php
    ----Select.php


    Autoload file:
    PHP Code:
    // Register __oddzLibAutoload function
    spl_autoload_register("__oddzLibAutoload");

    function 
    __oddzLibAutoload($className) {
        
        if( 
    preg_match"/^Oddz\_/"$className ) ) {
            
            
    $libRoot realpath dirname __FILE__ ) ) . "/";
            
    $classPath $libRoot str_replace "_""/"$className );

            if (
    is_file $classPath ".class.php" )) {
                require (
    $classPath ".class.php");
            } else if (
    is_file $classPath ".interface.php" )) {
                require (
    $classPath ".interface.php");
            } else if (
    is_file $classPath ".abstract.php" )) {
                require (
    $classPath ".abstract.php");
            }
        }


    Example usage:
    PHP Code:
    require '../lib/autoload.php';

    $form = new Oddz_Form();
    $form->addElement(new Oddz_Form_Element_Text('title'));
    $form->addElement(new Oddz_Form_Element_TextArea('content')); 
    If you're using PHP 5.3 you could use namespaces as well, which would reduce the class names' length.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •