eden/system

Eden file and folder component

1.0.3 2013-09-24 09:56 UTC

README

File and folder management in Eden is easy as calling methods. Both classes can be accessed as arrays as shown in the example below.

Figure 1. Access Files and Folders as arrays

//instantiate
$folder = eden('system')->folder('/some/path/anywhere');        

// adds more to the end (/some/path/anywhere/more)
$folder[] = 'more';         

// adds 'to' to the beginning (/to/some/path/anywhere)
$folder['prepend'] = 'to';  

// replaces 'anywhere' (the last path) with 'here' (/some/path/here)
$folder['replace'] = 'here';     

// returns the path with index of 1 (path)
echo $folder[1];                

// returns the last path ('anywhere')
echo $folder['last'];           

// returns the string path (/some/path/anywhere)
echo $folder;                   

Note: Files and folder classes extend Eden's string object. This means you can also call common string methods.

Figure 2. File Methods

$file = eden('system')->file('/some/path/to/file.php');     //instantiate

// returns the absolute path (or error)
$file->absolute();           

// adds 'there' to the end (/some/path/anywhere/there)
$file->append('there');      

// adds 'to' to the beginning (/to/some/path/anywhere)
$file->prepend('to');        

// replaces 'anywhere' (the last path) with 'here' (/some/path/here)
$file->replace('here');      

// removes the last path returns the value
$file->pop();                

// returns the path as an array
$file->getArray();           

// returns just the file name
$file->getName();                

// returns the folder name
$file->getFolder();              

// returns the file name without extension
$file->getBase();                

// returns the file extension
$file->getExtension();           

// returns the mime type
$file->getMime();                

// if this is a php file this will load it
$file->getData();                

// returns the contents of the file
$file->getContent();         

// returns the time file was updated
$file->getTime();                

// returns the size of the file
$file->getSize();                

// returns true if this is a real file
$file->isFile();             

// sets the content to 'something'
$file->setContent('something');  

// writes php data into the file
$file->setData(array(1, 2, 3));  

// updates the file time to now
$file->touch();                  

// removes the file
$file->remove();             

Figure 3. Folder Methods

//instantiate
$folder = eden('system')->folder('/some/path/to/folder');       

// returns the absolute path (or error)
$folder->absolute();     

// adds 'there' to the end (/some/path/anywhere/there)
$folder->append('there');    

// adds 'to' to the beginning (/to/some/path/anywhere)
$folder->prepend('to');      

// replaces 'anywhere' (the last path) with 'here' (/some/path/here)
$folder->replace('here');    

// removes the last path returns the value
$folder->pop();              

// returns the path as an array
$folder->getArray();     

// creates a folder with the permissions 777
$folder->create(777);        

// removes the folder
$folder->remove();           

// removes all files and folders in this folder
$folder->truncate();     

// returns just the folder name
$folder->getName();                      

// returns all folders found inside
$folder->getFolders();                   

// returns all folders found inside with names matching '.svn', recursive
$folder->getFolders('/\.svn/', true);     

// returns all files found inside that end with '.php' recursive
$folder->getFiles('/\.php$/', true); 

// removes all files with names matching 'test'
$folder->removeFiles('/test/');          

// removes all folders with names matching '.hidden', recursive
$folder->removeFolders('/\.hidden/', true); 

// returns true if this is really a folder
$folder->isFolder();       

Path Normalization

Whatever path format you pass into a File or Folder object, Eden will automatically convert it according to common pathing standards. The following describes different kinds of paths formats and how Eden automatically fixes it.

Figure 4. Fix My Paths

echo eden('system')->folder('some/path/to/folder');     //--> /some/path/to/folder
echo eden('system')->folder('/some/path/to/folder/');   //--> /some/path/to/folder
echo eden('system')->file('/some/path/to/file.php');    //--> /some/path/to/file.php
echo eden('system')->file('some/path//to/file.php');    //--> /some/path/to/file.php

Contributing to Eden

Setting up your machine with the Eden repository and your fork

  1. Fork the main Eden repository (https://github.com/Eden-PHP/System)
  2. Fire up your local terminal and clone the MAIN EDEN REPOSITORY (git clone git://github.com/Eden-PHP/System.git)
  3. Add your FORKED EDEN REPOSITORY as a remote (git remote add fork git@github.com:github_username/System.git)

Making pull requests

  1. Before anything, make sure to update the MAIN EDEN REPOSITORY. (git checkout master; git pull origin master)
  2. If PHP Unit testing is included in this package please make sure to update it and run the test to ensure everything still works (phpunit)
  3. Once updated with the latest code, create a new branch with a branch name describing what your changes are (git checkout -b bugfix/fix-twitter-auth) Possible types:
    • bugfix
    • feature
    • improvement
  4. Make your code changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")
  5. Once you've committed all the code to this branch, push the branch to your FORKED EDEN REPOSITORY (git push fork bugfix/fix-twitter-auth)
  6. Go back to your FORKED EDEN REPOSITORY on GitHub and submit a pull request.
  7. An Eden developer will review your code and merge it in when it has been classified as suitable.