GithubHelp home page GithubHelp logo

pragma-framework / core Goto Github PK

View Code? Open in Web Editor NEW
3.0 5.0 6.0 337 KB

Pragma Core Module for the Pragma Framework (ORM, Models, View, Controllers)

License: MIT License

PHP 100.00%
pragma orm pragma-framework php php-framework router template-engine mvc-framework

core's Introduction

core

Pragma Core Module for the Pragma Framework (ORM, Models, View, Controllers)

For a project skeleton using this module, see: https://github.com/pragma-framework/framework

stable packagist Build Status license

Installation

Using composer

$ composer require pragma-framework/core:dev-master

Auto-migrate database

Add in composer.json:

"scripts": {
	"post-package-install": [
		"Pragma\\Helpers\\Migrate::postPackageInstall"
	],
	"post-package-update": [
		"Pragma\\Helpers\\Migrate::postPackageUpdate"
	],
	"pre-package-uninstall": [
		"Pragma\\Helpers\\Migrate::prePackageUninstall"
	]
}

These scripts run DB migration for core and all associated plugins (ex: pragma-framework/historic, ...)

PostgreSQL & uidmysql

sudo su postgres -c "psql <db name> -c \"CREATE EXTENSION IF NOT EXISTS \\\"uuid-ossp\\\"\""

Run tests

$ vendor/bin/phpunit --bootstrap ./tests/bootstrap.config.sqlite.php tests/
$ vendor/bin/phpunit --bootstrap ./tests/bootstrap.config.mysql.php tests/

core's People

Contributors

cgiuliani avatar cyrilrouyer avatar kojuri avatar pips- avatar thomas-netlor avatar ti-tom avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

core's Issues

Model::pushHook - hooks can be pushed twice

core/Pragma/ORM/Model.php

Lines 467 to 468 in c0e2168

if(!is_null($hooks) && !isset($hooks[$hook])){
array_push($hooks, $hook);

The second part of the condition (!isset($hooks[$hook]) will always be true as in the next line we only push hook in the array without using a specific index. So currently hooks can be duplicated in the same hooks array.

Should we consider this an error and fix using unique index for each hook?

Model::find() & Model::all() may use static

See:

return self::forge()->where('id', '=', $id)->first();

return self::forge()->get_objects($idkey);

According to https://secure.php.net/manual/en/language.oop5.late-static-bindings.php#language.oop5.late-static-bindings.self, self in these contexts will be references to Model class.

The returned result is correct (i.e: the class used to class these static methods) thanks to QueryBuilder::first() & QueryBuilder::get_objects() using new static for objects instantiation, but IHMO, we should use static for consistency's sake.

PDO-SQlite requires consuming or closing resultset

We may encounter a problem with PDO & SQlite about locked database table.

See: http://blog.christosoft.de/2012/10/pdo-sqlite_table_locked_error/
And the upcoming commit: 7323e8e

Apparently, if a PDOStatement is not completely consumed by calling fetch() until there is no more results, or cleanly closed by 'closeCursor(), the table may stay in an unusable locked state.

I suspect the PDOStatement destructor to properly close the cursor, so this may arise only with consecutive queries in the same script (Saw this error while doing unit tests).

The problem will only appear if the user/developer directly use the DB object, otherwise our QueryBuilder and Modelabstraction would completely consume resultset (Maybe not with QueryBuilder::first() though, I didn't checked yet).

Should we provide a way to cleanly close PDO cursor?

PHPStan - Static code analysis

Tried this tool against master: https://github.com/phpstan/phpstan

Gave me a little report we can have a look at:

$ phpstan -V
PHPStan - PHP Static Analysis Tool 0.9.2
$ phpstan analyse Pragma/ module.php routes/
 18/18 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ---------------------------------------------------------------
  Line   Pragma/ORM/Relation.php
 ------ ---------------------------------------------------------------
  174    Access to an undefined property Pragma\ORM\Relation::$col_on.
  182    Access to an undefined property Pragma\ORM\Relation::$col_to.
  268    Function Exception not found.
 ------ ---------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------
  Line   Pragma/ORM/QueryBuilder.php
 ------ ------------------------------------------------------------------------------------------
  157    Method Pragma\ORM\QueryBuilder::get_resultset() invoked with 2 parameters, 0-1 required.
 ------ ------------------------------------------------------------------------------------------

 ------ ---------------------------------------------------------------------------
  Line   Pragma/ORM/Model.php
 ------ ---------------------------------------------------------------------------
  322    Call to static method generate() on an unknown class Webpatser\Uuid\Uuid.
  333    Access to an undefined property Pragma\ORM\Model::$id.
  351    Access to an undefined property Pragma\ORM\Model::$id.
 ------ ---------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------------------------------
  Line   Pragma/Router/Router.php
 ------ ------------------------------------------------------------------------------------------------------
  136    Call to static method isEnabled() on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  137    Call to static method getManager() on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  282    Anonymous function has an unused use $callback.
  294    Anonymous function has an unused use $callback.
 ------ ------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------
  Line   Pragma/Router/RouterException.php
 ------ ----------------------------------------------------------------
  25     Call to an undefined static method Exception::__constructor().
 ------ ----------------------------------------------------------------

 ------ -------------------------------------------------------------------------------------------------------------------------------------
  Line   Pragma/Helpers/Migrate.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------
  9      Parameter $event of method Pragma\Helpers\Migrate::postPackageInstall() has invalid typehint type Composer\Installer\PackageEvent.
  18     Parameter $event of method Pragma\Helpers\Migrate::postPackageUpdate() has invalid typehint type Composer\Installer\PackageEvent.
  27     Parameter $event of method Pragma\Helpers\Migrate::prePackageUninstall() has invalid typehint type Composer\Installer\PackageEvent.
  56     Instantiated class Composer\Repository\InstalledFilesystemRepository not found.
  56     Instantiated class Composer\Json\JsonFile not found.
 ------ -------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------
  Line   Pragma/Controller/BaseController.php
 ------ -----------------------------------------------------------------------------------------------------------
  24     Call to static method isEnabled() on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  25     Access to constant CSRF_TAG_NAME on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  27     Access to constant CSRF_TAG_NAME on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  28     Access to constant CSRF_TAG_NAME on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  29     Access to constant CSRF_TAG_NAME on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  32     Call to static method getManager() on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsManager.
  36     Instantiated class Pragma\Forms\CSRFTagsManager\CSRFTagsException not found.
  36     Access to constant TAG_REQUESTED_MESS on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsException.
  36     Access to constant TAG_REQUESTED on an unknown class Pragma\Forms\CSRFTagsManager\CSRFTagsException.
 ------ -----------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------
  Line   module.php
 ------ ----------------------------------------------------------------------------------------------------------------------
         Class Pragma\Core\Module was not found while trying to analyse it - autoloading is probably not configured properly.
 ------ ----------------------------------------------------------------------------------------------------------------------

 [ERROR] Found 27 errors

ORM model: save return object

Is it possible to return object ($this) when use fonction save() from ORM/Model.php

Ex:

$obj = obj::build([])->save(); $obj->doSomething();

Maybe in merge() also ?

Throw Exception on QueryBuilder::forge() without inherited class

While doing unit tests for QueryBuilder class, I realize I can not call the forge() method on the bare object.

Trying something like this:

$qb = QueryBuilder::forge();

Ends up in constructor being called without argument, giving a inconsistent QueryBuilder object missing a proper $table attribute value.

Changing this class to be abstract would not allow to build dummy object not linked to any table, as it is the main purpose of the QueryBuilder.

By the way, calling forge() with a class name as parameter may not completely solve this issue, the class name may be any existing class which may not be a valid children of QueryBuilder.

For this one, I suggest we use a is_subclass_of() on the string parameter if any. For the former, declare the class as abstract should be enough.

QueryBuilder::subwhere usage

I'm not sure how to make unit test for the QueryBuilder::subwhere(), do you have some usage examples, please?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.