initDatabase() public method

public initDatabase ( )
 public function setUp()
 {
     $md = new MetadataStorage(new PDO($GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']));
     $md->initDatabase();
     $tempFile = tempnam(sys_get_temp_dir(), '');
     if (file_exists($tempFile)) {
         @unlink($tempFile);
     }
     mkdir($tempFile);
     $this->tempFile = $tempFile;
     $document = new DocumentStorage($tempFile);
     $this->r = new RemoteStorage($md, $document);
 }
 public function setUp()
 {
     $ioStub = $this->getMockBuilder('fkooman\\IO\\IO')->getMock();
     $ioStub->method('getRandom')->will($this->onConsecutiveCalls(2, 3, 5, 7));
     $db = new PDO($GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']);
     $md = new MetadataStorage($db, '', $ioStub);
     $md->initDatabase();
     $tempFile = tempnam(sys_get_temp_dir(), '');
     if (file_exists($tempFile)) {
         @unlink($tempFile);
     }
     mkdir($tempFile);
     $this->tempFile = $tempFile;
     $document = new DocumentStorage($tempFile);
     $remoteStorage = new RemoteStorage($md, $document);
     $approvalManagementStorage = new ApprovalManagementStorage($db);
     $userAuth = new TestAuthentication();
     $apiAuth = new BearerAuthentication(new TestTokenValidator());
     $authenticationPlugin = new AuthenticationPlugin();
     $authenticationPlugin->register($userAuth, 'user');
     $authenticationPlugin->register($apiAuth, 'api');
     $this->r = new RemoteStorageService($remoteStorage, $approvalManagementStorage, new TestTemplateManager(), new RemoteStorageClientStorage(), new RemoteStorageResourceServer(), new TestApproval(), new TestAuthorizationCode(), new TestAccessToken(), array('server_mode' => 'production'), $ioStub);
     $this->r->getPluginRegistry()->registerDefaultPlugin($authenticationPlugin);
 }
Beispiel #3
0
 }
 $db = new PDO($dbDsn, $configReader->v('Db', 'username', false), $configReader->v('Db', 'password', false));
 // only enable templateCache when in production mode
 if ('development' !== $serverMode) {
     $templateCache = $configReader->v('templateCache', false, sprintf('%s/data/tpl', dirname(__DIR__)));
 } else {
     $templateCache = null;
 }
 $templateManager = new TwigTemplateManager(array(dirname(__DIR__) . '/views', dirname(__DIR__) . '/config/views'), $templateCache);
 $templateManager->setDefault(array('rootFolder' => $request->getUrl()->getRoot(), 'serverMode' => $serverMode));
 $md = new MetadataStorage($db);
 $approvalStorage = new PdoApprovalStorage($db);
 $authorizationCodeStorage = new PdoAuthorizationCodeStorage($db);
 $accessTokenStorage = new PdoAccessTokenStorage($db);
 if ($initDb) {
     $md->initDatabase();
     $approvalStorage->initDatabase();
     $authorizationCodeStorage->initDatabase();
     $accessTokenStorage->initDatabase();
 }
 $remoteStorage = new RemoteStorage($md, $document);
 $session = new Session('php-remote-storage', array('secure' => 'development' !== $serverMode));
 $userAuth = new FormAuthentication(function ($userId) use($configReader) {
     $userList = $configReader->v('Users');
     if (null === $userList || !array_key_exists($userId, $userList)) {
         return false;
     }
     return $userList[$userId];
 }, $templateManager, $session);
 $apiAuth = new BearerAuthentication(new DbTokenValidator($db), array('realm' => 'remoteStorage'));
 $authenticationPlugin = new AuthenticationPlugin();
Beispiel #4
0
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once dirname(__DIR__) . '/vendor/autoload.php';
use fkooman\Config\YamlFile;
use fkooman\Config\Reader;
use fkooman\RemoteStorage\MetadataStorage;
use fkooman\OAuth\Storage\PdoAccessTokenStorage;
use fkooman\OAuth\Storage\PdoAuthorizationCodeStorage;
use fkooman\OAuth\Storage\PdoApprovalStorage;
try {
    $configReader = new Reader(new YamlFile(dirname(__DIR__) . '/config/server.yaml'));
    $db = new PDO($configReader->v('Db', 'dsn', false, sprintf('sqlite:%s/data/rs.sqlite', dirname(__DIR__))), $configReader->v('Db', 'username', false), $configReader->v('Db', 'password', false));
    $metadataStorage = new MetadataStorage($db);
    $metadataStorage->initDatabase();
    $approvalStorage = new PdoApprovalStorage($db);
    $approvalStorage->initDatabase();
    $authorizationCodeStorage = new PdoAuthorizationCodeStorage($db);
    $authorizationCodeStorage->initDatabase();
    $accessTokenStorage = new PdoAccessTokenStorage($db);
    $accessTokenStorage->initDatabase();
} catch (Exception $e) {
    echo $e->getMessage() . PHP_EOL;
    exit(1);
}