using doctrine with codeigniter - codeigniter

I am planning to use doctrine to write a module of my app which is built with codeigniter.
I have a very basic question :
lets say I have a table called "user", with doctrine generate-models from db, 3 classes are generated BaseUser.php, User.php and UserTable.php. Now as I saw in the examples they use User class straigtaway. Should I be doing this ? I need additional business functionality for the user objects. So should I create a codeigniter model user_model and then use User class inside it (aggregation) or somehow extend user class ( i dont know how this will be done as user_model extends model)
Am little confused on this one and cannot locate any appropriate literature for the same.
Any help would be appreciated.
thanks in advance,

For anyone who is interested - I’ve posted up a project starter on my blog - a dev ready incorporation of the following technologies:
ExtJS : client side JS library,
CodeIgniter : presentation + domain tier,
Doctrine : ORM data layer framework
Some features of this project starter are:
- CodeIgniter Models have been replaced with Doctrine Records
- Doctrine is loaded into CI as a plugin
- RoR type before and after filters….
- Doctrine transactions automatically wrapped around every action at execution time (ATOMIC db updates)
Basic Role based security (I think Redux may be in there as well?)
Simply extract, hook up the database.php config file and viola…. You can start coding your layouts, views and models. Probably a few things to iron out - but enjoy!
Hope it helps
GET IT AT: http://thecodeabode.blogspot.com

Check out this info on Doctrine_Table class.
To your 3 generated files:
BaseXXX.php:
Holds the definition of your models so that Doctrine is able to handle the operations on the database. This class tells the ORM what colums are available, their types, advaned functions (like Timestampable,...) and more. You should not put your own data into this file since it will be over-written when re-creating the models from the database.
XXX.php:
Your actual model. This won't be re-created with each new generation process and this is were you keep most of your code. You can overwrite functions of the BaseXXX.php if you have to.
XXXTable.php:
Check my link from the top, This gives you access to the table itself. Personally, I do not use it that often since I put most of the code into XXX.php.
Of course you can create new classes and use them inside your XXX.php file. In order to actually do something with the data (save, read,...) you need classes that are connected (exteneded) from Doctrine's classes.
edit: also check this on a more infos with extending from the Doctrine_Table class

Related

accessing table metadata from embedded Teiid server

I have embedded Teiid 12.3 in a Spring Boot application. I want to get into the metadata of my VDB in order to generate a diagram using graphviz-java. I assume that if I have a org.teiid.metadata.Table object, I can call getIncomingObjects() to get references to tables that table depends on. I just can't figure out how to navigate from the EmbeddedServer to the Table objects.
I looked into using the administration API available via EmbeddedServer.getAdmin(). From there, I can call getVDBs(), and from there I can navigate down to getModels(), but below that level there is only the model source via getSourceMetadataText(). I also tried subclassing EmbeddedServer to make getVDBRepository() public. I can call getVDBRepository()*.getModels(), but it returns the same Model objects only get me access to the source definition of the models, not the runtime metadata model.
I tried getVDBRepository().getSystemStore() and VDBRepository.getODBCStore(), but those MetadataStores are not for the VDB I have deployed.
I haven't found any examples by Google, Teeid JIRA, Teiid forum, or StackOverflow to help me.
Take look at [1] the getSchema method on Admin API, this method returns the string form of the metadata, however you can grab Schema object for object form. If you do not want that way, Teiid also exposes system catalog using many SYS tables, you can issue SQL queries to grab the metadata of schemas and schema items in a VDB. One for internal access, another is from external access.
BTW one of users created a dependency diagram tool that may be useful if you are trying to do something similar. See [2]. Let me know if you interested in pushing that further.
[1] https://github.com/teiid/teiid/blob/master/runtime/src/main/java/org/teiid/runtime/EmbeddedAdminImpl.java#L544-L557
[2] https://github.com/teiid/metadata-catalog-ui

How to mock User model within composer package development tests?

I started creating a laravel 5.8 based modular API framework for our company which should be extended using composer packages.
Now I stumbled over the problem to test each package by itself (each package has it's own GIT project of course) if the package needs to have access to the User model given in the base framework (App/Models/User).
There will be various packages naturally depending on the User model such as specific auth modules.
Unfortunately testing also gets more complex because we are using GraphQL (Lighthouse).
So how should this be done? I tried mocking App/Models/User with a User model contained in the tests folder of my package, but this did not work as expected:
$this->userMock = \Mockery::mock('CompanyName\\PackageName\\Tests\\User');
$this->app->instance('App\\Models\\User', $this->userMock);
When, after that, posting a GraphQL request the resolver method throws a Class App\Models\User does not exist error.
I am quiet new to testing with phpunit so maybe I am just missing something here?
Edit:
I just found out that the error message above is displayed because the User model is also referenced within the GraphQL schema file.
So I there is any solution out there it has to somehow "emulate" the not existing User model class for the whole request lifecycle I guess...
Ok I finally solved my problem which was more conceptual wise I guess. As the user model is pretty strongly tied to the (core) package I want to test, I have now moved the model into the package itself and removed it from the base project.
This has the advantage that the "end user developer" doesn't even see and has to cope with the user model which is handles by the package anyway.
Now I can test the package independently and only have to put a line of documentation into the README to tell, that a user has to change the auth.providers.users.modelvalue to let laravel use the appropriate model (e.g. CompanyName\\PackageName\\Models).
If there will be other packages extending the user model, they will have to depend on the core package (which they should either way) and can extend the model class and tell the user to update auth.providers.users.model again. This way it is also quiet transparent to see which user model is used currently.
For the GraphQL / Lighthouse part I have added the following code to the boot method of the package's service provider to make lighthouse know about new models within the package automatically:
$lighthouseModels = config('lighthouse.namespaces.models');
array_push($lighthouseModels, 'CompanyName\\PackageName\\Models');
config([
'lighthouse.namespaces.models' => $lighthouseModels
]);
This can be repeated for every package adding models as well so lighthouse knows about all of them.

The place where to execute custom code while migration

Guys please advice. I'm release new version of software and there were some braking changes, to order properly update from previous version i need to execute custom code on applying certain migration.
Update steps are:
1. Get all records from one table
2. Foreach thought them and create appropriate record in other tables
I prefer to use my "Manager" from business logic layer(core)
I don't know yet how to implements this. Please give me advice or code sample would be better.
So far I see 3 places where I can put these logic.
1. Migration file itself. in EF layer.
2. Migrator project.
3. Seed file in EF layer.
According to #Avin Kavish recommendation I've created method in Migrator project with additional flag "-migrateToV2" and create method which use my manager from core to update data properly. Thanks.

add attributes to user entity in jhipster

I want to add some attributes to the user entity, when I googled about it, I found a similar question :
How to modify existing entity generated with jhipster?
when I followed the steps in this post, I couldn't find the file user.json anywhere as #Roberto montioned
1) Edit the json file representing your entity (add/remove field, the syntax is pretty easy, check in the end of the file if is required any change to the general entity properties like 'fieldsContainOneToMany'...), you'll find it in:
<jhipster_root_folder>/.jhipster/entityName.json
How can I solve this ?
I think the best solution is a compromise between the two solutions offered by #Pedro and #alcuvi (who references to the JHipster Documentation):
First, create an "ExtendedUser" entity with the additional fields (don't forget to use git, you will have to undo this/delete the entity). A one-to-one relationship to "User" is not necessary.
After that, you can copy many parts from "ExtendedUser" to the other parts of the JHipster Application:
Liquibase changelog columns (also add them to users.csv)
ExtendedUser.java → User.java and UserDTO.java
extendedUser-dialog.* → register.html/.controller.js and settings.html/.controller.js
Adapt AccountResource.java and UserService.java (and UnitTests if you use them). This step is mostly done by using getters and setters copied in the step before. JHipster Documentation (https://jhipster.github.io/tips/022_tip_registering_user_with_additional_information.html) might be helpful here.
Delete the "ExtendedUser" Entity (using git, or manually, see also: How to delete an entity after creating it using jhipster?)
The *advantages* are:
Using JHipster code generation capabilities
No additional entity (which comes with new DB tables and many files)
I hope this information will help other developers in the future!
The User entity is the entity used by JHipster to manage all user management stuff, like email, passwords, etc., so you won't find a User.json file, since that is an automatically generated entity. Those .json files are only created when you run yo jhipster:entity <entityName>.
In order to add/remove fields to the User entity, you'll have to do it manually, that means editing User.java, creating a liquibase changeset and modify all related files in the UI as needed.
The official documentation of jhipster (version 4) have an entry about this.
https://jhipster.github.io/tips/022_tip_registering_user_with_additional_information.html
In summary...
Its manual solution.
The proposed solution is to create an entity with the fields you want to add to user and linked to it with a one to one relationship.
Alternatively
If you create a ExtendedUser with new fields with JDL-Studio the jhipsterimport-jdl command is going to create "extendedUser" option on entity menu where you can set values for those fields and linked to the user you want.
I thinks is not the best solution...
What about inheritance? Just extend built-in User class with new fields. For example, public class ExtendedUser extends User. And replace User class with ExtendedUser in code. Update dto, service, etc. Also you can use class casting where it's required. What thoughts?

Can I extend the DB library of CodeIgniter 2?

I want to add custom data to the insert method of the db library to automatically do some timestamp work and other processing. I know I can extend controller and model defaults with MY_, but what about the DB?
This isnt the right answer, because you can extend your CI Database class, i did it!
Just follow this tut and you will get it working!
https://github.com/EllisLab/CodeIgniter/wiki/Extending-Database-Drivers
im just have problems trying to use two database connections when the second connection is loaded with $this->db->load(), just had this problem, everyelse work like a charm!
No: see http://codeigniter.com/user_guide/general/creating_libraries.html, there is an explicit warning that the DB class can't be extended.

Resources