https://github.com/magnatefw/magnate
Framework for WordPress plugin development.
https://github.com/magnatefw/magnate
framework php wordpress wordpress-development
Last synced: 5 months ago
JSON representation
Framework for WordPress plugin development.
- Host: GitHub
- URL: https://github.com/magnatefw/magnate
- Owner: magnatefw
- License: gpl-3.0
- Created: 2021-05-02T20:15:32.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-22T22:18:42.000Z (almost 5 years ago)
- Last Synced: 2025-07-12T22:46:28.343Z (11 months ago)
- Topics: framework, php, wordpress, wordpress-development
- Language: PHP
- Homepage:
- Size: 151 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Magnate 0.9.8
## TODO
1. Write the docs.
2. Add CSRF-protection.
3. Add field aliases to Active Record.
## How to use
### Entry Point
You can create an entry point class by inheriting **\Magnate\EntryPoint**. An entry point class intended for create a singleton that contains all or significant part of the plugin logic.
The init() method can be overrided if you want to add some logic to object construction.
You must create **\Magnate\Injectors\EntryPointInjector** instance before create an entry point object. It is pretty simple: all you need is a root directory and URL of your plugin.
**NOTICE:** The init() method must be protected and return *$this*.
### Migrations
You can add migrations class by inheriting **\Magnate\Tables\Migration** with overrided up() method that contains all table creating logic. Table name can be determined by calling the table() method. Call the field() method to add field, the index() method to add index and the entry() method to add an entry to empty table.
**NOTICE:** The up() method must be protected and return *$this*.
### Active Record
An AR model can be created by inheriting **\Magnate\Tables\ActiveRecord**. You can get a single model instance by find() method or took a collection of instances by where(), order() or limit() methods.
Example:
```php
[
'condition' => 'LIKE %s',
'value' => '%test%'
],
'text' => [
'condition' => '= %s',
'value' => 'this is testing text'
]
],
[
'value' => [
'condition' => '= %s',
'value' => 'This is test.'
]
]
]
)->order(['key' => 'DESC'])->limit(1)->get()->all();
```
The get() method returns us a **\Magnate\Tables\ActiveRecordCollection** object, and all() method retrieves a list of model instances.
Of course, you can save the model state in database by calling the save() method.