예제 #1
0
파일: Debug.php 프로젝트: ssrsfs/blg
 public function output(Pagemill_Data $data, Pagemill_Stream $stream)
 {
     Typeframe::Timestamp('Starting debug output');
     $debug = new Pagemill_Data();
     $timestamps = Typeframe::GetTimestamps();
     $tdata = array();
     if ($timestamps) {
         $begin = $timestamps[0]->time();
         foreach ($timestamps as $t) {
             //$dump .= "{$t->action()}: " . ($t->time() - $begin) . "<br/>";
             $tdata[] = array('action' => $t->action(), 'time' => $t->time() - $begin);
         }
     }
     $debug['timestamps'] = $tdata;
     $debug['memory_used'] = memory_get_usage();
     $debug['memory_used_real'] = memory_get_usage(true);
     $debug['includes'] = get_included_files();
     $debug['querycount'] = Dbi_Source::QueryCount();
     $debug['templates'] = Pagemill::ProcessedTemplates();
     // TODO: Get template files
     $debug['data'] = $data;
     $this->_recurseTines($debug);
     $include = new Typeframe_Tag_Include('include', array('template' => '/pagemill/tag/debug.html'));
     $include->process($debug, $stream);
 }
예제 #2
0
파일: Typeframe.php 프로젝트: ssrsfs/blg
 /**
  * Get a reference to the global database interface.
  * @return Dbi_Source
  */
 public static function Database()
 {
     return Dbi_Source::GetGlobalSource();
 }
예제 #3
0
파일: dbexport.inc.php 프로젝트: ssrsfs/blg
$args = array_slice($argv, 2);
if (count($args)) {
    $classes = array();
    foreach ($args as $cls) {
        if (class_exists($cls) && is_subclass_of($cls, 'Dbi_Schema')) {
            $classes[] = $cls;
        } else {
            die("ERROR: The {$cls} does not exist or is not a schema/model class.\n");
        }
    }
} else {
    $files = scandir(TYPEF_SOURCE_DIR . '/classes/BaseModel');
    if (substr($file, 0, 1) != '.') {
        foreach ($files as $file) {
            if (pathinfo($file, PATHINFO_EXTENSION) == 'php') {
                $cls = 'BaseModel_' . pathinfo($file, PATHINFO_FILENAME);
                if (class_exists($cls) && is_subclass_of($cls, 'Dbi_Schema')) {
                    $classes[] = $cls;
                } else {
                    die("ERROR: The {$cls} does not exist or is not a schema/model class.\n");
                }
            }
        }
    }
}
foreach ($classes as $cls) {
    echo "Exporting {$cls}...\n";
    $mod = new $cls();
    $src = Dbi_Source::GetModelSource($mod);
    $src->configureSchema($mod);
}
예제 #4
0
파일: unit.php 프로젝트: ssrsfs/blg
 public function tearDown()
 {
     // Revert to the real source for news articles
     Dbi_Source::SetModelSource(new Model_News_Article(), $this->_oldSource);
 }
예제 #5
0
파일: import.php 프로젝트: ssrsfs/blg
<?php

date_default_timezone_set('America/New_York');
$mtime = microtime(true);
define('TYPEF_START_TIME', $mtime);
require_once TYPEF_SOURCE_DIR . '/autoload.php';
require_once TYPEF_SOURCE_DIR . '/libraries/functions.php';
Pagemill_Doctype::SetTemplateDoctypeClass('Typeframe_Doctype');
// TODO: Set up a way to make the framework database-independent.
$source = new Dbi_Source_MySql(TYPEF_DB_HOST, TYPEF_DB_USER, TYPEF_DB_PASS, TYPEF_DB_NAME);
Dbi_Source::SetGlobalSource($source);
// TODO: Find logical places to register the class handlers and expressions.
function useModel($model)
{
    return $model->select();
}
function useFormHandler($form)
{
    return array('fields' => $form->fields(), 'errors' => $form->errors());
}
function useFormField($field)
{
    return $field->data();
}
Pagemill_Data::ClassHandler('Dbi_Model', 'useModel');
Pagemill_Data::ClassHandler('Form_Handler', 'useFormHandler');
Pagemill_Data::ClassHandler('Form_Field', 'useFormField');
Pagemill_Data::RegisterExprFunc('default_date', 'Typeframe_ExprFunc::default_date');
Pagemill_Data::RegisterExprFunc('default_date_time', 'Typeframe_ExprFunc::default_date_time');
Pagemill_Data::RegisterExprFunc('default_date_time_w_seconds', 'Typeframe_ExprFunc::default_date_time_w_seconds');
Pagemill_Data::RegisterExprFunc('skin_path', 'Typeframe_Skin::SkinPath');
예제 #6
0
파일: Source.php 프로젝트: ssrsfs/blg
 /**
  * Set the DBI source to be used for all models that have not specified
  * their own data source.
  * @param Dbi_Source $source
  */
 public static function SetGlobalSource(Dbi_Source $source = null)
 {
     self::$_GlobalSource = $source;
 }
예제 #7
0
파일: Install.php 프로젝트: ssrsfs/blg
 /**
  * Install a package from the local directory.
  * @param string $tarball The path to the package file.
  * @param array|bool $force An array of files that should be overwritten even if the local copy is customized,
  * or TRUE if they should always be overwritten, or FALSE if they should never be overwritten.
  * @param bool $getDependencies If true, look for dependency updates on the provider.
  * @return array|boolean An array of strings describing the installation or false if the installation failed.
  */
 public static function Package($tarball, $force = array(), $getDependencies = false)
 {
     $result = array();
     if (!file_exists($tarball)) {
         throw new Exception("File {$tarball} does not exist");
     }
     $dir = tempnam(sys_get_temp_dir(), 'TYPEF_');
     unlink($dir);
     mkdir($dir);
     exec('tar --directory=' . $dir . ' -zxf ' . $tarball);
     $package = '';
     // Download dependencies if a provider is available
     if (TYPEF_PROVIDER && $getDependencies) {
         if (file_exists("{$dir}/source/packages")) {
             $packages = scandir("{$dir}/source/packages");
             $dependencies = array();
             foreach ($packages as $package) {
                 if (substr($package, 0, 1) != '.') {
                     $pathinfo = pathinfo($package);
                     if ($pathinfo['extension'] == 'xml') {
                         $dependencies[] = $pathinfo['filename'];
                         self::_GetDependencies($dir, $pathinfo['filename'], $dependencies);
                     }
                 }
             }
         }
     }
     $ftp = new Typeframe_File();
     $packed = scandir("{$dir}/source/packages");
     foreach ($packed as $pf) {
         $pathinfo = pathinfo($pf);
         if ($pathinfo['extension'] == 'xml') {
             $package = $pathinfo['filename'];
             self::_CopyFiles($ftp, $dir, '', $package, $force);
             // Always copy the package file
             $ftp->copy("{$dir}/source/packages/{$pf}", '/source/packages/' . $pf);
         }
     }
     // Make writeable directories
     $packageFiles = array();
     if (file_exists("{$dir}/source/packages")) {
         $packageFiles = scandir("{$dir}/source/packages");
     }
     foreach ($packageFiles as $pf) {
         if (substr($pf, 0, 1) != '.') {
             if (pathinfo($pf, PATHINFO_EXTENSION) == 'xml') {
                 $xml = Pagemill_SimpleXmlElement::LoadFile("{$dir}/source/packages/{$pf}");
                 foreach ($xml->updir as $updir) {
                     $updir = trim("{$updir}");
                     $parts = explode("/", $updir);
                     $curDir = '';
                     foreach ($parts as $part) {
                         if ($part) {
                             $curDir .= "/{$part}";
                             if (!file_exists(TYPEF_DIR . $curDir)) {
                                 $ftp->mkdir($curDir);
                                 $ftp->chmod(0777, $curDir);
                             }
                         }
                     }
                 }
             }
         }
     }
     $ftp->close();
     // Update base models if package contained any
     if (file_exists("{$dir}/source/classes/BaseModel")) {
         $modelFiles = scandir("{$dir}/source/classes/BaseModel");
         foreach ($modelFiles as $mf) {
             if (substr($mf, 0, 1) != '.') {
                 $pathinfo = pathinfo($mf);
                 if ($pathinfo['extension'] == 'php') {
                     $cls = "BaseModel_{$pathinfo['filename']}";
                     $mod = new $cls();
                     $src = Dbi_Source::GetModelSource($mod);
                     $src->configureSchema($mod);
                 }
             }
         }
     }
 }
예제 #8
0
파일: model.php 프로젝트: ssrsfs/blg
 public function tearDown()
 {
     // Revert to the original global source
     Dbi_Source::SetGlobalSource(self::$OldSource);
 }
예제 #9
0
파일: Record.php 프로젝트: ssrsfs/blg
 /**
  * Delete the record.
  */
 public function delete()
 {
     // TODO: Should we check to see if the record is dirty first?
     if (!$this->exists()) {
         return;
     }
     $this->_model->notify(Dbi_Model::EVENT_BEFOREDELETE, $this);
     $cls = get_class($this->_model);
     $clone = new $cls();
     $primary = $clone->index('primary');
     if (is_null($primary)) {
         throw new Exception("Model does not have a primary key");
     }
     foreach ($primary['fields'] as $key) {
         $clone->where("{$key} = ?", $this->_data[$key]);
     }
     Dbi_Source::GetModelSource($this->_model)->delete($clone);
     $this->_exists = false;
     $this->_valid = false;
 }
예제 #10
0
파일: Model.php 프로젝트: ssrsfs/blg
 public function __construct()
 {
     $this->source = Dbi_Source::GetModelSource($this);
 }