1. instantiated once when injected. access the same instance whenever / wherever referenced. ie. global scope
2. instantiated each time it is injected. a fresh instance is referenced. i.e local scope
definition of each class to be injected, could be via:1. anonymous function (fresh object each time)2. new classname (same object each time)
Currently, the hive caters for the second type, but when creating the definitions, all the classes are instantiated immediately, not as needed. The anonymous function type is not supported at all.
@Richard Catto:1. instantiated once when injected. access the same instance whenever / wherever referenced. ie. global scopeIf your class extends Prefab, you automatically have the instance() method, so $f3->set('obj',myClass::instance()); should instantiate the class and give you the same object every time you retrieve via $f3->get('obj');
2. instantiated each time it is injected. a fresh instance is referenced. i.e local scopeI don't understand what you mean by "local scope", but $f3->set('obj',new MyClass) should give you a new instance every time.
definition of each class to be injected, could be via:1. anonymous function (fresh object each time)2. new classname (same object each time)
Currently, the hive caters for the second type, but when creating the definitions, all the classes are instantiated immediately, not as needed. The anonymous function type is not supported at all.If you wrap your object instantiation in an anonymous function, then you defer the process:$f3->set('deferred',function() {return myClass::instance();});$deferred=$f3->get('deferred');var_dump($deferred());What exactly do you need that can't already be done?
@Richard Catto, after reading your initial post, I had no idea of what you had in mind. I googled "dependency injection container" and stumbled on that, which made things even worse :P
But after @bcosca's answer, the picture got clearer. It looks like "dependency injection container" is some form of lazy loading with global dependencies.
In that case, I think the following should answer your question:
class MyClass extends Prefab {public $name='foo';private $db;function __construct(\DB\SQL $db,$name=NULL) {$this->db=$db;if ($name)$this->name=$name;}}$db=new \DB\SQL('mysql:host=127.0.0.1;port=3306;dbname=test;','user','pwd');$f3->global=function() use($db) {return MyClass::instance($db);};echo $f3->global()->name; //foo$f3->local=function($name) use($db) {return new MyClass($db,$name);};echo $f3->local('baz')->name; //bazecho $f3->local('bar')->name; //bar});In that example:
- the database connection $db is a global "dependency"
- $f3->global() always returns the same instance/singleton (what you call "global instance")- $f3->local() always returns a fresh instance (what you call "local instance")Note that the first use ("global") requires your class to extend \Prefab.
On Thursday, December 11, 2014 1:34:05 AM UTC+1, bcosca wrote:
Those Phalcon docs are much clearer. Then I think you can easily implement your own DI container. See here for a quick example.I don't see the use of adding it in the framework though.What do you think?On Thursday, December 11, 2014 7:39:21 PM UTC+1, Richard Catto wrote:
Those Phalcon docs are much clearer. Then I think you can easily implement your own DI container. See here for a quick example.I don't see the use of adding it in the framework though.What do you think?On Thursday, December 11, 2014 7:39:21 PM UTC+1, Richard Catto wrote:
True. The Registry already does the job of locating shared services, so if it has to be part of the framework, it should belong to the Registry.But there's still one thing I don't fully understand: what would be a use case of non-shared services? Can someone provide an example?BTW, where did that topic about software patterns go?
On Friday, December 12, 2014 10:25:55 AM UTC+1, ikkez wrote:
Thanks for your clarification.I was wondering why "$mail=$di->mail()" would be better than "$mail=new Mail()". It looks like the DI container is a way of flattening signature/dependencies differences, which may come in handy when integrating a significant amount of third party libraries. The price to pay is that dependencies become harder to track.Also I realize that it could be used as a way of defining "shortcuts" for common/frequent actions. E.g:$di->set('sendMailToCustomer',function($to,$subject,$html){$smtp = new SMTP('127.0.0.1',25,'ssl','user','pw');$smtp->set('To',$to);$smtp->set('Subject',$subject);$body=Template::instance()->render('mail-customer.html',NULL,array('message'=>$html));$smtp->send($body);});$di->set('log',function($msg,$target='app'){$log=new Log($target.'.log');$log->write($msg);});Then in your app:
$di->sendMailToCustomer('jo...@doe.me','Your new password','...');
3.3.1 will be released before year-end.
$f3->set( 'AUTOLOAD' , '/includes/' );
$f3['AUTOLOAD'] = '/includes/';
$f3->AUTOLOAD = '/includes/';
function reroute($url,$permanent=FALSE) {
$par=$this->get('PARAMS');
unset($par[0]);
foreach ($par as $key=> $val) {
$url= str_replace("@$key", $val, $url);
}
if (PHP_SAPI!='cli') {
if (preg_match('/^(?:@(\w+)(?:(\(.+?)\))*|https?:\/\/)/',
$url,$parts)) {
if (isset($parts[1])) {
if (empty($this->hive['ALIASES'][$parts[1]]))
user_error(sprintf(self::E_Named,$parts[1]));
$url=$this->hive['BASE'].
$this->hive['ALIASES'][$parts[1]];
if (isset($parts[2]))
$this->parse($parts[2]);
$url=$this->build($url);
}
}
else
$url=$this->hive['BASE'].$url;
header('Location: '.$url);
$this->status($permanent?301:302);
die;
}
$this->mock('GET '.$url);
}
/** Initialize Log system */$f3['LOGS'] = 'logs/';
$f3['logger'] = new Log('error.log');
$f3['logger']->write( 'Hello' );
foreach ( $f3['names'] as $key => $value) {
.... Do somethings
}
You mean ArrayAccess ?I mean ArrayObject :)Better than ArrayAccessAnd why don't use in Base ?
$f3['names'] is already working now
, since you left the array object on accessing the first key ;)You mean ArrayAccess ?I mean ArrayObject :)Better than ArrayAccessAnd why don't use in Base ?
feeling good with ArrayAccess:
Sample: :)
/** Initialize Log system */$f3['LOGS'] = 'logs/';
$f3['logger'] = new Log('error.log');
$f3['logger']->write( 'Hello' );
I think we can fly with ArrayObject :DExample:
foreach ( $f3['names'] as $key => $value) {
.... Do somethings
}
On Saturday, January 17, 2015 at 1:14:14 AM UTC+3:30, Farhad Sakhaei wrote:
You mean ArrayAccess ?I mean ArrayObject :)Better than ArrayAccess
And why don't use in Base ?
On Saturday, January 17, 2015 at 12:51:54 AM UTC+3:30, ikkez wrote:
- add ikkez's Cortex +100!
$old = array(1,2,3);
$new = [1,2,3];
2015 is round the corner........
I disagree about this mad rush about having a framework, ANY framework, in it own namespace. A framework is the keystone of your app; it is not an optional component. Neither is it a library you can use on demand; it embodies the entire structure of your app. Every app component will not run properly without it. As such, it is only logical that it be in the root namespace where it belongs.
Be careful what you wish for. Lots of use statements can be annoying.
On Wednesday, February 18, 2015 at 7:25:35 PM UTC+8, Steve Cove wrote:
/about=specificFunctionForAboutPage
/contact=specificFunctionForContactPage
;user added pages, pulled from database
/@page=pageController->show
I disagree with this mad rush about having a framework, ANY framework, in it own namespace. A framework is the keystone of your app; it is not an optional component. Neither is it a library you can use on demand; it embodies the entire structure of your app. Every app component will not run properly without it. As such, it is only logical that it be in the root namespace where it belongs: on the same level as your app; no, the basis of everything.
Be careful what you wish for. Lots of use statements can be annoying.
On Wednesday, February 18, 2015 at 7:25:35 PM UTC+8, Steve Cove wrote:
[
'before' => [
'beforeroute', //resolve to CONTROLLER->beforeroute (or a generic beforeroute() function if CONTROLLER->beforeroute doesn't exist)
'generic_function', //resolve to generic_function (assuming CONTROLLER->generic_function doesn't exists)
'Middleware->intercept' //resolve to Middleware->intercept (not CONTROLLER)
],
'after' => [
'afterroute' //resolve to CONTROLLER->afterroute (or...)
]
]
// Execute pre-route hook if any if ($obj && $hooks && in_array($hook='beforeroute',$hooks) && method_exists($func[0],$hook) && call_user_func_array(array($func[0],$hook),$args)===FALSE) return FALSE; // Execute callback $out=call_user_func_array($func,$args?:array()); if ($out===FALSE) return FALSE; // Execute post-route hook if any if ($obj && $hooks && in_array($hook='afterroute',$hooks) && method_exists($func[0],$hook) && call_user_func_array(array($func[0],$hook),$args)===FALSE) return FALSE; return $out;
// Call route handler$result=$this->call($handler,array($this,$args), 'beforeroute,afterroute');
Help make F3 better. Your active participation is truly welcome.
What i haven't seen identified is WHO is f3 being pitched at?
The higher up the ability level aimed at will correspond with less of the population using it
On the Docs you know when you buy a new printer or other gissmo and the book is a hundred pages plus long but there is included a three page leaflet for the impatient (which i always use) then a brief complete overview somewhere at the start of the docs might be helpful.
<cfoutput query="classes_students_pets" group="class_id">
<!--- groups the query and returns one item per class_id (as long as the result is ordered by class_id) --->
Class Name: #class_name#
Students:
<cfoutput group="student_id">
<!--- loops through all rows that have the same class_id, --->
#student_name# has pets: <cfoutput>
<!--- lists all rows that match student_id and class_id--->
#pet_name#
</cfoutput>
</cfoutput>
</cfoutput>
$f3->set('div',
array(
'coffee'=>array('arabica','barako','liberica','kopiluwak'),
'tea'=>array('darjeeling','pekoe','samovar')
)
);
2015 is round the corner. 3.3 has reached its peak. Don't worry, it won't be abandoned. 3.3.1 will be released before year-end. Now we're preparing the specs for the next incarnation of the framework you've come to know and love. In light of this announcement, we would like to engage everyone in a healthy discussion of what 4.0 should be like. Each feature request must have a justification. Code volunteers are also welcome and must be stated in the entry.To start off, a code review is now an absolute necessity.* I plan on cleaning up the hive's built-in variables. It's starting to be a mess and some variables add fat where there should be none.* Event triggers/handlers should be unified. A standard mechanism must be developed. Those before... after... on... prefixes should be eliminated.* PHP 5.4 will be the new minimum. 5.3 has already reached its end of life. No use beating a dead horse.If you have ideas/suggestions about how the future F3 should behave, we're all ears. Bear in mind, the basic single-file functionality will still be there and will always conform to our non-fat philosophy. Everything else will be a plugin.Remember, this should be a healthy discussion. Feature comparison with other frameworks is fine but should never be a basis for a feature request. A rationale should stand by itself.
* Alias: allow array of parameters
{{ 'list', 'a=5' | alias }}
or a bit more dynamic:
{{ @name, 'a=5,b='.@id | alias }}
In /.htaccess:
#Sass Parser: anything /css/FILENAME.css -> FILENAME.scss
RewriteRule ^css/(.*).css?$ style.php/$1.scss [NC,L]
In root folder, I have style.php:
<?php
require "lib/scssphp/scss.inc.php";
$scss = new scssc();
$scss->setFormatter("scss_formatter");
$server = new scss_server("ui", null, $scss);
$server->serve();
?>
In my HTML, I use:
<link rel="stylesheet" href="/css/style.css">
In /ui I have my file of actual SCSS code: /ui/style.scss
And everything just works. SCSSPHP just checks if the file needs to be recompiled and does it transparently, otherwise sends the cached version.
That's very exciting news. I hope there will be multiple hooks addable per trigger with priority? As well ability to remove actions?
On Aug 9, 2015 5:52 PM, "bcosca via Fat-Free Framework" <f3-framework+APn2wQfMLSpXhGq3PUv...@googlegroups.com> wrote:
>
> Some code for an on() and off() hook capability is in the works. It is definitely coming. What is not definite is the release date, although there is a chance it may appear before 4.0 comes along.
>
>
> On Monday, August 10, 2015 at 7:07:30 AM UTC+8, ethanpil wrote:
>>
>> I was thinking today that perhaps we can add a hook / action system, similar to this:
>>
>> http://docs.slimframework.com/hooks/how-to-use/
>>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Fat-Free Framework" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/f3-framework/IuwlCpNvyMs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to f3-framework...@googlegroups.com.
> To post to this group, send email to f3-fra...@googlegroups.com.
> Visit this group at http://groups.google.com/group/f3-framework.
> For more options, visit https://groups.google.com/d/optout.
Whilst i agree that official tutorials are a great way to introduce a frameworks features, it is not really that feasible with a microframework like F3.The very ethos of the framework is that it is a minimalist collection of components that can be used as you require.
Any non trivial application will be based on userland code and conventions - for example every app i have built uses a form of MVC at its base, but i doubt any one user (or core contributor) could agree on how to do MVC with fatfree.
Similarly, authentication and authorization are another core component of most large apps, but how you handle that is up to you - there is no official way.Even the excellent Cortex ORM is an optional plugin maintained outside the official repository - its just an option among many (doctorine, redbean, raw sql, etc).
I would personally love to see some application structure baked into the core, but i doubt the maintainers will go for this - the more opinionated a framework becomes, it either becomes more specialized (eg looses its general purpose nature) or more heavily engineered.
2015 is round the corner. 3.3 has reached its peak. Don't worry, it won't be abandoned. 3.3.1 will be released before year-end. Now we're preparing the specs for the next incarnation of the framework you've come to know and love. In light of this announcement, we would like to engage everyone in a healthy discussion of what 4.0 should be like. Each feature request must have a justification. Code volunteers are also welcome and must be stated in the entry.To start off, a code review is now an absolute necessity.* I plan on cleaning up the hive's built-in variables. It's starting to be a mess and some variables add fat where there should be none.* Event triggers/handlers should be unified. A standard mechanism must be developed. Those before... after... on... prefixes should be eliminated.* PHP 5.4 will be the new minimum. 5.3 has already reached its end of life. No use beating a dead horse.If you have ideas/suggestions about how the future F3 should behave, we're all ears. Bear in mind, the basic single-file functionality will still be there and will always conform to our non-fat philosophy. Everything else will be a plugin.Remember, this should be a healthy discussion. Feature comparison with other frameworks is fine but should never be a basis for a feature request. A rationale should stand by itself.Help make F3 better. Your active participation is truly welcome.