Skip to content

Instantly share code, notes, and snippets.

@andrewwheal
Created September 2, 2014 11:48
Show Gist options
  • Save andrewwheal/c71cafafaf5d448abd66 to your computer and use it in GitHub Desktop.
Save andrewwheal/c71cafafaf5d448abd66 to your computer and use it in GitHub Desktop.
PhpStorm File Templates
<?php
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end
class Controller_${NAME} extends \Controller_Template {
public function action_index() {
}
}
<?php
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end
class Controller_${NAME} extends \Controller_Template {
public function action_index() {
${NAME} = Model_${MODEL}::find('all');
}
public function action_view($id = false) {
${MODEL} = Model_${MODEL}::find($id);
}
}
<?php
namespace Fuel\Migrations;
class ${Migration_Name}
{
public function up()
{
try {
\DB::start_transaction();
\DBUtil::add_fields(
'${Migration_Table}',
[
'id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'foreign_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
'int' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
'bool' => ['type' => 'tinyint', 'constraint' => 1, 'unsigned' => true, 'default' => 0],
'varchar' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'created_at' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'null' => true],
'updated_at' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'null' => true],
]
);
\DB::commit_transaction();
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Up Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Up Successfully: ' . __FILE__, 'green');
}
public function down()
{
try {
\DB::start_transaction();
\DBUtil::drop_table('${Migration_Table}');
\DB::commit_transaction();
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Down Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Down Successfully: ' . __FILE__, 'green');
}
}
<?php
namespace Fuel\Migrations;
class ${Migration_Name}
{
public function up()
{
try {
\DB::start_transaction();
\DBUtil::create_table(
'${Migration_Table}',
[
'id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
'foreign_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
'int' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
'bool' => ['type' => 'tinyint', 'constraint' => 1, 'unsigned' => true, 'default' => 0],
'varchar' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'created_at' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'null' => true],
'updated_at' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'null' => true],
],
['id'],
false,
'InnoDB',
'utf8_unicode_ci'
);
\DB::commit_transaction();
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Up Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Up Successfully: ' . __FILE__, 'green');
}
public function down()
{
try {
\DB::start_transaction();
\DBUtil::drop_table('${Migration_Table}');
\DB::commit_transaction();
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Down Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Down Successfully: ' . __FILE__, 'green');
}
}
<?php
namespace Fuel\Migrations;
class ${Migration_Name}
{
public function up()
{
try {
\DB::start_transaction();
\DB::insert('${Migration_Table}')
->columns(['foo', 'bar', 'baz'])
->values(
[
'a',
'b',
'c',
]
)
->values(
[
'x',
'y',
'z',
]
);
\DB::insert('${Migration_Table}')
->columns(['foo', 'bar', 'baz'])
->values(
[
[
'a',
'b',
'c',
],
[
'x',
'y',
'z',
],
]
);
\DB::insert('${Migration_Table}')
->set(
[
'foo' => 'a',
'bar' => 'b',
'baz' => 'c',
]
)
->set(
[
'foo' => 'x',
'bar' => 'y',
'baz' => 'z',
]
);
\DB::commit_transaction();
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Up Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Up Successfully: ' . __FILE__, 'green');
}
public function down()
{
try {
\DB::start_transaction();
\DB::delete('${Migration_Table}')
->where();
\DB::commit_transaction();
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Down Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Down Successfully: ' . __FILE__, 'green');
}
}
<?php
namespace Fuel\Migrations;
class ${Migration_Name}
{
public function up()
{
try {
// DO STUFF
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Up Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Up Successfully: ' . __FILE__, 'green');
}
public function down()
{
try {
// UNDO STUFF
} catch (\Exception ${DS}e) {
\DB::rollback_transaction();
\Cli::error(sprintf('Down Migration Failed - %s - %s', ${DS}e->getMessage(), __FILE__));
return false;
}
\Cli::write('Migrated Down Successfully: ' . __FILE__, 'green');
}
}
<?php
namespace ${Namespace};
class ${Class_Name} extends \Orm\Model
{
protected static ${DS}_table_name = '${Table_Name}';
protected static ${DS}_properties = [
'id' => [
'data_type' => 'int'
],
'data' => [
'data_type' => 'varchar',
'label' => 'Random Data',
'null' => true,
'validation' => [
'max_length' => [254],
'valid_string' => ['alpha', 'newlines', 'spaces'],
],
'form' => [
'type' => 'textarea',
'maxlength' => 254,
],
],
'option' => [
'data_type' => 'enum',
'label' => 'Random Option',
'options' => ['one' => 'one', 'two' => 'two', 'three' => 'three'],
'validation' => [
'required',
],
'form' => [
'type' => 'radio',
'options' => ['one' => 'one', 'two' => 'two', 'three' => 'three'],
],
],
'bar_id' => [
'data_type' => 'int',
'label' => 'Bar',
'validation' => [
'required',
],
'form' => [
'type' => 'select',
'class' => 'chosen',
'options' => [],
],
],
'created_at' => [
'data_type' => 'int',
'form' => ['type' => false],
],
'updated_at' => [
'data_type' => 'int',
'form' => ['type' => false],
],
];
protected static ${DS}_belongs_to = [
'bar' => [
'key_from' => 'bar_id',
'model_to' => 'Example\Model_Bar',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => false,
],
];
protected static ${DS}_has_one = [
'baz' => [
'key_from' => 'id',
'model_to' => 'Model_Bat',
'key_to' => 'foo_id',
'cascade_save' => true,
'cascade_delete' => true,
],
];
protected static ${DS}_has_many = [
'bats' => [
'key_from' => 'id',
'model_to' => 'Test\Model_Bat',
'key_to' => 'foo_id',
'cascade_save' => true,
'cascade_delete' => true,
],
];
protected static ${DS}_many_many = [
'quxes' => [
'key_from' => 'id',
'key_through_from' => 'foo_id',
'table_through' => 'example__foo_qux',
'key_through_to' => 'qux_id',
'model_to' => 'Example\Model_Qux',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => true,
],
];
protected static ${DS}_observers = [
'Orm\Observer_Validation' => [
'events' => ['before_save'],
],
'Orm\Observer_Typing' => [
'events' => ['before_save', 'after_save', 'after_load'],
],
'Orm\Observer_CreatedAt' => [
'events' => ['before_insert'],
'mysql_timestamp' => false,
'property' => 'created_at',
],
'Orm\Observer_UpdatedAt' => [
'events' => ['before_save'],
'mysql_timestamp' => false,
'property' => 'updated_at',
],
];
}
<?php
\Autoloader::add_namespace('${Namespace}', __DIR__ . '/classes/');
#if (${Module_Name} != "")
\Config::set('module_paths.${Module_Name}', __DIR__ . '/modules/');
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment