Yii Framework Forum: Guidelines For Extension Authoring - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Guidelines For Extension Authoring Discussion about guidelines for extensions for Yii2

#1 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 566
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 06 May 2013 - 10:28 AM

/* continued from this topic: http://www.yiiframew...review-version/ */

@Qiang: I urge you to create guidelines for extensions, before too many Yii2 extensions are getting released.
I really appreciate the work of the developers, but it's also a crucial point to have a common base for extensions.
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

#2 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 09-March 09
  • Location:*.php

Posted 06 May 2013 - 11:33 AM

@schmunk: We have https://github.com/y...ork-code-style. This is enough for the people who make the extensions for preview version. I do not think people who need guideline will release extensions for preview version of framework. So guideline can well wait until alpha.
No good, no bad, only consequence.
0

#3 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 566
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 06 May 2013 - 11:45 AM

Yes, you're right. I know that we're "only" at Public Preview and that this feature is under development.
For me the extension concept is just the most important core feature of Yii.

And the way extensions are developed and included in an app influences their usage and maintenance a lot.

I'll stay patient :)
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
2

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,343
  • Joined: 17-January 09
  • Location:Russia

Posted 06 May 2013 - 01:57 PM

schmunk, started a wiki article:

https://github.com/y...ion-development

Any suggestions?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 May 2013 - 02:11 PM

Extensions must use migrations, if it requires additions/mods to the db.
No home grown sql scripts or installers, please. :)
"Less noise - more signal"
4

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,343
  • Joined: 17-January 09
  • Location:Russia

Posted 06 May 2013 - 02:54 PM

Added.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#7 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 May 2013 - 03:56 PM

I am not sure if this fits here - and I admit that I haven't checked out how migrations work in Yii2, but I write like this in the migration script for a module I am working on:
class m130226_185845_initial_tables extends CDbMigration
{
	public function up()
	{

    	if(! isset(Yii::app()->getDb()->tablePrefix)) { Yii::app()->getDb()->tablePrefix = ''; };

    	$this->createTable('{{wikipage}}', array(
        	'id' => 'pk',


If a table prefix is not set, I set the prefix to an empty string, and then carry on using {{tablename}} so that my module will respect the tableprefix if it has been set.

That should probably be added as well?
"Less noise - more signal"
0

#8 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 566
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 06 May 2013 - 04:51 PM

@samdark: You can review my additions here: https://github.com/s...964ee0a99553f5f

See also this page for a nice sample workflow for github wikis.
Just add my wiki fork as a remote: https://github.com/s...2/yii2.wiki.git and merge.

Note: There are many points which need more clarification. You may also not agree with everything ;) but I thought it's better to add everything I have in mind now,
Maybe we should also open a separate topic for the upcoming discussion, but I'll leave this up to you.
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

#9 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 May 2013 - 05:21 PM

View Postschmunk, on 06 May 2013 - 04:51 PM, said:

Maybe we should also open a separate topic for the upcoming discussion, but I'll leave this up to you.

Done. I split the topic in two, if you don't mind. ;)
"Less noise - more signal"
0

#10 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,343
  • Joined: 17-January 09
  • Location:Russia

Posted 06 May 2013 - 05:25 PM

jacmoe
1.

Quote

Extension code MUST not contain additional (bundled) extensions, e.g. Yii Framework, CSS framework

What about jquery plugins? What if extension provides such a framework?

2. Why "src" dir? Does that mean that extension should be under vendor/libName/src namespace?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#11 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 May 2013 - 05:34 PM

I assume that you are asking Schmunk, not me Samdark. :)

However, I think he means that the extension must not ship with other Yii extensions (like Yiistrap, etc.)

Not sure what he means by CSS frameworks..
Would be prudent to include the framework if you are doing an extension like Yiistrap or Foundation for Yii.

In some worlds, those would be handled by a composer script, of course, but - like YiiBootstrap - the extensions could be modified to suit the extension / ease the integration.

And, no matter how hard Schmunk tries, not everyone is fond of using composer. ;p

That needs to be clarified.

Of course, if the extension ships with Yii framework and other readily available Yii extensions, that is wrong.
"Less noise - more signal"
0

#12 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 May 2013 - 05:43 PM

Having looked at Schmunk's additions, I think it's safe to say that I never will release an official Yii2 extension, ever. ;)

((just kidding))

I think that extensions for Yii should use English, in code and in docs.
If they are in Chinese, Russian, etc. they should be clearly marked as such.
I hope there is a language filter for Yii extension repository?

I also think that they must be hosted on a public repository so that the extension registry can point to it.
That would prevent stale downloads, etc.

[edit]
Most of the additions are sane, but many can only be recommendations IMO.
"Less noise - more signal"
0

#13 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 09-March 09
  • Location:*.php

Posted 07 May 2013 - 12:27 AM

Quote

Extension code SHOULD use namespaces in the format `vendorName/extensionName` (headless camel-case)


Partially agree. Namespace `creocoder\yii\behaviors\nestedSet` fits this rule?

I think rule should be more flexible. Like `vendorName\...\extensionName`.
No good, no bad, only consequence.
0

#14 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 566
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 07 May 2013 - 02:55 AM

Thanks, for your feedback, my additions are not carved in stone :)

View Postsamdark, on 06 May 2013 - 05:25 PM, said:

What about jquery plugins? What if extension provides such a framework?

Sure, there's a difference - sorry about the CSS Framework, this has to be clarified. And with jQuery you're also hitting the point!
What I mean is that an extension must not include a complete CSS framework if it's just a eg. plugin like chosen, select2 or editable. And also not jQuery for sure. The exception is the CSS Framework extension oder JavaScript lib extension itself.
But jQuery is part of the core and therefore treated in another way than bootstrap. Bootstrap may become part of the core, but what's about Zurb Foundation, mootools, etc. then? @jacmoe: Right ;)

That said, I sometime stumbled upon incompatibilities with jQuery versions in Yii 1.x. With scriptMap you can overcome this problem, but wouldn't it be nicer just to define the version of "yii2-jquery" you want to have or just download it and place it into your app? You could also remove "yii2-bootstrap" and include "yii2-zurb-foundation" - without composer, may do this by hand, but the code has to be structured in a certain way.

And on the other hand, that an extension must not include existing (PHP, Yii) extension code, take YiiBooster and yii-boostrap for example.
In the first releases YiiBooster included a slightly modified version of yii-bootstrap, which would have lead to incompatibility issues. That must not happen.
I am inspired by the Unix philosophy Rule of Composition and Rule of Separation.

If such a thing happens, we should use the composer.json file to define either a require(ment) or conflict(s).
Please, you don't need to actually use(!) composer. This file would just contain a very basic set of meta information in JSON format, which would make it also very easy to create a custom Yii2 package repository. I would make this a requirement , not just for the sake of composer, more because it would take a ton of load off the core-devs maintaining the extension platform.

View Postsamdark, on 06 May 2013 - 05:25 PM, said:

2. Why "src" dir? Does that mean that extension should be under vendor/libName/src namespace?

Don't has to be `src/`, but as far as I understand the PSR-0 Examples you have to have kind of an entry point for autoloading your classes via a namespaces. Note: I am not experienced with namespaces, so I may overlook something here.
But to give you also an example here, this one line enables me to use any class from packages, which support autoloading via namespaces, without adding an alias or import - even in Yii 1.x.

How will we "install" an extension in Yii2?

View Postjacmoe, on 06 May 2013 - 05:34 PM, said:

However, I think he means that the extension must not ship with other Yii extensions (like Yiistrap, etc.)

Not sure what he means by CSS frameworks..
Would be prudent to include the framework if you are doing an extension like Yiistrap or Foundation for Yii.

In some worlds, those would be handled by a composer script, of course, but - like YiiBootstrap - the extensions could be modified to suit the extension / ease the integration.

And, no matter how hard Schmunk tries, not everyone is fond of using composer. ;p

That needs to be clarified.

Of course, if the extension ships with Yii framework and other readily available Yii extensions, that is wrong.

100% correct :D


View Postjacmoe, on 06 May 2013 - 05:43 PM, said:

Having looked at Schmunk's additions, I think it's safe to say that I never will release an official Yii2 extension, ever. ;)

((just kidding))

I think that extensions for Yii should use English, in code and in docs.
If they are in Chinese, Russian, etc. they should be clearly marked as such.
I hope there is a language filter for Yii extension repository?

I also think that they must be hosted on a public repository so that the extension registry can point to it.
That would prevent stale downloads, etc.

[edit]
Most of the additions are sane, but many can only be recommendations IMO.

I also totally agree here. btw: I tried to use the word SHOULD instead of MUST on the "debatable" points ;D .
And for sure we should provide something like a downloadable extension template to start with.
Ah, that would be a very nice yiic command or gii module!

View Postcreocoder, on 07 May 2013 - 12:27 AM, said:

Partially agree. Namespace `creocoder\yii\behaviors\nestedSet` fits this rule?

I think rule should be more flexible. Like `vendorName\...\extensionName`.

Sure sorry, like in PSR-0: \<Vendor Name>\(<Namespace>\)*<Class Name>
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
1

#15 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 566
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 14 May 2013 - 02:23 PM

@samdark: Please let me know if there are points which keep you from merging.
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

#16 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,343
  • Joined: 17-January 09
  • Location:Russia

Posted 15 May 2013 - 04:40 AM

Lack of time to review it properly.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#17 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 566
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 15 May 2013 - 04:43 AM

Ok, thanks for your feedback.
Looking forward to discuss this again...
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users