コード例 #1
0
ファイル: Autoload.php プロジェクト: hlegius/PlainMVC
/**
 * Loading unknown classes
 * @param string $class
 */
function __autoload($class)
{
    if (file_exists(\Library\PlainMVC\Core\PlainConfig::getInstance()->getRootDirectory() . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php')) {
        require_once \Library\PlainMVC\Core\PlainConfig::getInstance()->getRootDirectory() . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
    } elseif (file_exists(\Library\PlainMVC\Core\PlainConfig::getInstance()->getLibraryDirectory() . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php')) {
        require_once \Library\PlainMVC\Core\PlainConfig::getInstance()->getLibraryDirectory() . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
    }
}
コード例 #2
0
ファイル: Assertion.php プロジェクト: hlegius/PlainMVC
 /**
  * Initialize assertion class
  * @return void
  */
 public function __construct()
 {
     if (is_null(self::$rootconfig)) {
         $spyc = new Spyc();
         self::$rootconfig = $spyc->loadFile(PlainConfig::getInstance()->getConfigDirectory() . DIRECTORY_SEPARATOR . 'root.yml');
     }
     $this->status = self::$rootconfig['Plain']['assert_' . self::$rootconfig['Plain']['application']];
     if ($this->getStatus() == self::ENABLED) {
         assert_options(ASSERT_ACTIVE, 1);
         assert_options(ASSERT_WARNING, 0);
         assert_options(ASSERT_BAIL, 0);
         assert_options(ASSERT_CALLBACK, array(__CLASS__, 'fail'));
     } else {
         assert_options(ASSERT_ACTIVE, 0);
     }
 }
コード例 #3
0
ファイル: PlainTemplate.php プロジェクト: hlegius/PlainMVC
 /**
  * Initialize facade
  */
 public function __construct()
 {
     $templatesDirs = array();
     // Looking for Templates directories
     foreach (PlainConfig::getInstance()->getModulesDirectories() as $moduleDirectory) {
         foreach (scandir($moduleDirectory) as $file) {
             $currentFile = new String($moduleDirectory . DIRECTORY_SEPARATOR . $file);
             $file = new String($file);
             if (!is_dir($currentFile)) {
                 continue;
             }
             if ($file->equals(PlainConfig::getInstance()->getTemplatesDirPattern())) {
                 $templatesDirs[] = realpath($currentFile);
             }
         }
     }
     $twigLoader = new \Twig_Loader_Filesystem($templatesDirs);
     self::$template = new \Twig_Environment($twigLoader, array('cache' => PlainConfig::getInstance()->getTempDirectory() . DIRECTORY_SEPARATOR . 'tpl_cache'));
     $this->variables = new \ArrayObject();
 }
コード例 #4
0
 /**
  * Index action for sandbox
  * @internal url: http://yoursite/index/sandbox
  * @param $request
  */
 public function indexAction(PlainHttpRequest $request)
 {
     $address = new Sandbox\Address();
     $user = new Sandbox\User();
     echo 'Por enquanto, tudo oka !';
     $user = new Sandbox\User();
     $user->setName('Garfield');
     DoctrineConfig::getInstance()->persist($user);
     DoctrineConfig::getInstance()->flush();
     $user = new Sandbox\User();
     $user->setName('Helio');
     DoctrineConfig::getInstance()->persist($user);
     DoctrineConfig::getInstance()->flush();
     echo "User saved!";
     /* @var $garfield \Application\Sandbox\User */
     $garfield = DoctrineConfig::getInstance()->find('\\Application\\Sandbox\\User', 1);
     $userRepository = DoctrineConfig::getInstance()->getRepository('\\Application\\Sandbox\\User');
     $hlegius = new \ArrayObject($userRepository->findByName('Helio'));
     echo '<p>&nbsp;</p>';
     echo "The first username is called as {$garfield->getName()}<br />";
     echo "The user hlegius is called as {$hlegius->offsetGet(0)->getName()}";
     $configs = Core\PlainConfig::getInstance()->getApplicationConfig();
     var_dump($configs['type']);
 }
コード例 #5
0
ファイル: PlainHttpRequest.php プロジェクト: hlegius/PlainMVC
 /**
  * Throw not found class exception
  * @return void
  */
 private function throwClassNotFoundException($dirname)
 {
     $subdirectory = str_replace($this->getPathBase() . DIRECTORY_SEPARATOR . 'web', '', $dirname);
     $subdirectory = empty($subdirectory) ? 'Index' : $subdirectory;
     $subdirectories = explode(DIRECTORY_SEPARATOR, $subdirectory);
     $suffix = join("", array_map("ucwords", $subdirectories));
     $modulesPath = PlainConfig::getInstance()->getModulesDirectories();
     foreach ($modulesPath as $modulePath) {
         $moduleFiles = scandir($modulePath . DIRECTORY_SEPARATOR . 'Controllers');
         if (!in_array("Default{$suffix}Controller.php", $moduleFiles)) {
             continue;
         }
         $defaultCall = "Application\\Modulo\\Controllers\\Default{$suffix}Controller";
         $reflectionModule = new \ReflectionClass($defaultCall);
         if ($reflectionModule->hasMethod('indexAction')) {
             $defaultClass = new $defaultCall();
             return $defaultClass->{'indexAction'}($this, PlainHttpResponse::getInstance());
         }
     }
     $actionName = PlainHttpRequest::getInstance()->getAction() ? PlainHttpRequest::getInstance()->getAction()->__toString() : 'notFound';
     $class = new PlainNotFoundActionController();
     $class->{$actionName . 'Action'}($this, PlainHttpResponse::getInstance());
     return;
 }
コード例 #6
0
}
$config = new Configuration();
$config->setMetadataCacheImpl($cache);
## Doctrine Metadata configuration
// Annotation
$driverImpl = $config->newDefaultAnnotationDriver(Core\PlainConfig::getInstance()->getApplicationDirectory());
// Yaml files
//$driver = new YamlDriver(array(dirname(__FILE__) . '/../schema/'));
//$config->setMetadataDriverImpl($driver);
// XML files
//$driver = new \Doctrine\ORM\Mapping\Driver\XmlDriver(array('/path/to/xmlfiles'));
//$config->setMetadataDriverImpl($driver);
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir(Core\PlainConfig::getInstance()->getApplicationDirectory());
$config->setProxyNamespace(View\PlainHttpRequest::getInstance()->getNamespaceFor(Core\PlainConfig::getInstance()->getApplicationDirectory()));
if ($settings['type'] != "production") {
    $config->setAutoGenerateProxyClasses(true);
} else {
    $config->setAutoGenerateProxyClasses(false);
}
$connectionOptions = array('driver' => $settings['database']['driver'], 'host' => $settings['database']['host'], 'dbname' => $settings['database']['dbname'], 'user' => $settings['database']['user'], 'password' => $settings['database']['pass']);
class DoctrineConfig
{
    private static $em;
    public function __construct($connectionOptions, $config)
    {
        if (!self::$em instanceof \Doctrine\ORM\EntityManager) {
            self::$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
        }
    }