lewsid / dinkly Goto Github PK
View Code? Open in Web Editor NEWThe biggest little PHP framework
License: MIT License
The biggest little PHP framework
License: MIT License
In BaseDinklyBuilder
, the buildModule()
function echoes the success message even when if(mkdir($module_folder))
throws a warning. This happened when I tried to run gen_module and there was no module folder in the app directory.
Add support for table indexes
It would be nice to have a class to represent each app, so that app-wide tweaks can be applied to all modules beneath it.
PHPUnit vs SimpleTest?
loadComponent should be isolating it's context to prevent collision.
Devise a solution for integrating Dinkly-specific plugins.
Warnings are thrown on gen_models.php for plugins that don't have a config/schemas folder.
Currently, it will default to dinkly if there is more than one database.
This works fine when running the blanket gen_models.php tool, but not for the singular gen_model.php
Improve support for a wider range of API headers - ie, for specific error states.
It would be good to have a redirect
method that handles redirecting the user to a view based on app, module, view, etc.
The other method would handle locating the controller method to execute and calling it.
We need a LICENSE.md and this may be the appropraite contents: https://opensource.org/licenses/MIT
loadModule can't handle jumping across apps when the controllers are named the same in more than one app. Cannot redeclare class.
Hydrate's second parameter, $hasDB, defaults to false, and if this is the case and you run a save on the model, the error:
Call to a member function quote() on a non-object in...
is thrown. Possibly check that $this->db is not null when save is called, and if it is, throw a more meaningful exception?
When using app gen tool, also add configs to config.yml
In schema .yml files if no length parameter is specified for a type that requires it, invalid sql is generated, but no error is thrown for the user that specifies what to fix or what went wrong.
PHP Deprecated: Function create_function() is deprecated in /Users/joe/Dropbox (Bluehouse Group)/projects/path/classes/core/custom/Dinkly.php on line 597
That's in a override of the convertToCamelCase in BaseDinkly. The overridden function would throw the same notice.
Add attribute for setting default values to schema files.
I've gotten used to setting dynamic page titles in the Dinkly class, but there has to be a better way.
In numerous places in BaseDinkly.php
PHP 7.2 Function create_function() is deprecated
Loading any page that requires a data model will throw Array to String conversion notices and eventually crash
This is because of a new variable syntax.
// old meaning // new meaning
$foo->$bar['baz'] $foo->{$bar['baz']} ($foo->$bar)['baz']
In hydrate(), update() and insert(), anything using the $foo->$bar[$property] syntax has to be updated to $foo->{$bar[$property]}
Using the word 'key' for a table name in a model's YAML causes problems. Adding a filter for such things directly to Dinkly would be very cool
Based on conversations with Joe, refactor session app name handling:
$_SESSION['app_name']['app_name']
Perhaps by extending the capabilities of AppControllers to be aware of the app name.
This is easy enough to get around by overriding the call to update and adjusting the final line of the query build:
$query .= " where id='" . $this->Id . "'";
on line 132 of DinklyDataModel to what you need. But just wanted to give you a heads up. Possibly allow specification of (compound) primary key in the config schema for the model?
Update error output to suggest user try '?nocache=1'
You run into this error when you try to run gen_models.php
without having first run these commands on your machine:
sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
It would be nice if we handled the exception and suggested running these commands. We almost always have to do this when setting up new machines, and that's so infrequent that it's hard to remember that you have to run these two.
The module name part of the URL causes a PHP controller file to be included. We should block any attempts to navigate around the file system by requesting a path with ../../ etc. It's probably a stretch because the filename needs to end in Controller.php but even so, it's an easy hole to patch in BaseDinkly::getContext. It could potentially be an issue if coupled with something like a careless image upload which allowed a PHP file to be uploaded.
Still using version 2...
It's very hard to reason about where controller functionality comes from because Dinkly instantiates controller objects, and those controller objects also inherit from Dinkly. I think it'd be better to separate Dinkly and controllers, and then have the latter inherit from an abstract controller class:
abstract class Controller
{
private $app;
private $module;
public function getApp()
{
// Gets app
}
public function getModule()
{
// Gets module
}
public function json($data, int $status = 200, array $headers = [])
{
// Returns JsonResponse object
}
public function file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
{
// Returns BinaryFileResponse object
}
public function render(bool $with_layout = true)
{
// Returns Response object with HTML content
}
}
Couple things to figure out:
I think it's important that this class be extensible in some way. Like if I wanted to start using a template engine like twig, I could create a twig
method somewhere that would make it available on all controllers.
I guess what I find lacking is that the ORM support doesn’t an easy way to query against related tables. I get not wanting to hydrate all the joined data, but being able to stick a related field in the where clause (and then the ORM would implicitly add a join to the query) and then only returning/hydrating one model would save me from having to write 75% of the raw queries I end up writing.
Or even just getWith, but with a table_name.field_name convention. The schema would have to be aware of these relationships to make something like that happen, though. I don’t think it would be a huge lift, and I can imagine ways that it could be layered on top of what we have know without breaking anything.
I can do this or create a pull request if you like.
There are two issues with $_SERVER['APPLICATION_ROOT']. The first is mostly cosmetic I guess.
We have this in bootstrap.php.
$_SERVER['APPLICATION_ROOT'] = dirname(__FILE__) . '/../';
The resulting path ends in /config/../ and any calculated path contains /config/../ .
If nothing else, this just looks untidy when debugging.
I suggest changing it to
$_SERVER['APPLICATION_ROOT'] = realpath(dirname(__FILE__) . '/..');
That produces a simple clean path like /var/apps/myapp
rather than /var/apps/myapp/config/../
The other issue is that $_SERVER['APPLICATION_ROOT']
is used inconsistently in terms of whether or not a trailing slash is expected. In the many (most?) places, the appended path adds another slash so there are many places where the resulting path is calculated with a double slash like /var/apps/myapp/config/..//somepath
. This seems to work but is untidy and I suspect might even be ambiguous on some file systems.
If we use my realpath suggestion above, we need to find all uses of $_SERVER['APPLICATION_ROOT']
and make sure that a slash is added or alternatively make the bootstrap line this:
$_SERVER['APPLICATION_ROOT'] = realpath(dirname(__FILE__) . '/..') . '/';
and remove the slash from appended paths. Either way is okay but we should do one or the other.
Instead of:
public function loadDefault()
Let's have it include parameters:
public function loadDefault($parameters)
I think it is a better example out of the gate of usage that way.
In BaseDinklyDataCollection::getWith() we have added $db as the last argument, but this will look funky as we add other arguments. I propose we move it to the first argument and update all of our codebases that use this.
It'd be nice if, when creating a new model instance, any default values that are set on insert are also set on the model instance.
For example, say we have the following config file:
table_name: dinkly_user
registry:
- id
- username: { type: varchar, length: 64, allow_null: false }
- is_cool: { type: boolean, length: 1, allow_null: false, default: 1}
Then, somewhere in the code, we went to used the generated model for this table.
$user = new User($db);
$user->setUsername('CoolGuy1');
$user->save();
After saving, the $user
object's id
property has been set, but the isCool
property is null, even though the record's field is set to 1 in the DB. It'd be nice if the model's property was automatically set to 1.
I think this could be implemented in one of two ways.
Add another property to the automatically generated base-prefixed model classes. You could call it $defaults
. Then, when constructing a new model instance, any properties listed in this array would automatically be set equal to the default value.
Backfill the model after inserting. I'm not sure if there's a more efficient way to do it, but after inserting the record, you could run a select query using the lastInsertId
and then populating the values into the model.
PHP Warning: Missing argument 1 for BaseDinkly::filterFiles(), called in /Users/joe/Dropbox (Bluehouse Group)/projects/path/classes/core/base/BaseDinkly.php on line 943 and defined in /Users/joe/Dropbox (Bluehouse Group)/projects/path/classes/core/base/BaseDinkly.php on line 736
I think the argument should be removed from this function's signature. I don't see any indication that it should be passed something.
In BaseDinklyDataModel.
Need to add a return true; after $this->hydrate() in the initWith function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.