Paul M. Jones

Don't listen to the crowd, they say "jump."

Solar 1.0.0alpha3 Released

The alpha3 version of the Solar Framework for PHP5 has been released; you can get it from the usual locations. Of note, this will be the last alpha release of Solar; I expect to have a beta released within the next 8 weeks or so.

This entry is cross-posted from the Solar blog.

I can't believe that almost a whole year has passed since alpha2 was released. In that time we have made some significant changes to how some major Solar components work. You can read the class-by-class change notes if you like, but after a year, they are quite extensive. To point out the highlights, I'll give a broad overview in this post.

Before I do that, I would like to thank one person in particular who made this release what it is: Jeff Moore of Mashery. Jeff has done more on this release than any other contributor, making huge strides in the Model and other packages through his code, reporting, revisions, and (admittedly) nagging of me to make things better. Thank you, Jeff, for everything you have done to make this release possible.

There are lots of others who contributed in important ways, most of whom are noted in the change log with their specific achievements:

  • Jon Elofson
  • Anthony Gentile
  • Robert Gonzalez
  • Tomasz Holeksa
  • Antti Holvikari
  • Ray Kolbe
  • Kalkin
  • Dmytro Konstantinov
  • Clay Loveless
  • Rodrigo Moraes
  • Nicholas Sloan
  • Jeff Surgeson
  • Richard Thomas
  • Matthew Turland
  • Robert Treat
  • Kevin Wagner

Thanks, guys, for all your effort and attention. The project is better for your having been involved. :-)

Model Changes

Nothing has been lost. Solar models still:

  • recognize has-one, belongs-to, and has-many relationships;
  • allow eager- and lazy-fetching of related records;
  • support SingleTableInheritance;
  • save only the changed data, not the whole record;
  • perform data filtering at save() time; and
  • generate automatic form hints from the table columns.

However, much has been added, including performance enhancements across the board. Below are only a few of the highlights; for a full rundown, please review the change notes.

Less-Active Table, More-Active Record

Previously, the table-based Solar_Sql_Model class retained a lot of TableModule-like behavior from its predecessors (Solar_Sql_Table, Solar_Sql_Entity, PEAR DB_Table, etc). When combined with the Solar_Sql_Model_Record logic for inserts and updates, it became difficult to track which parts were doing what.

To remedy this, the Model class has had most of the manipulation logic stripped out of its insert/update/etc methods, and all of that special logic has been placed in the Record class. That makes the Model more like a TableDataGateway, in that it will insert and update the data you give it without attempt to massage it; as a corollary, the Record becomes more like an ActiveRecord implementation.

Many-to-Many

We have added "has-many-through" relationship descriptors. This means that models now recognize many-to-many relationships through an explicit association model.

Saving Related Records

When you save a record, it now wires up all the related record IDs for you, setting all the necessary primary key information automatically. In partcular, saving a "has-many-through" will wire up not only the related records on the foreign side of the association table, but also the related records on the association table itself.

For the "has" relationships, it then saves each of the related records and collections for you:

  • has-one records are saved as they are;
  • has-many collections are saved as they are; and
  • has-many-through collections are checked for additions and
    removals against the association table, and are saved or deleted
    as necessary; this includes saving the records on the foreign side
    of the association table

Note that automatic saving of related records does not occur on "belongs-to" relationships. You still have to save those on your own; they are necessarily precursors to the existence of the current record or collection.

Eager Fetching

Eager fetching performance has been improved in many common cases. We now have dual strategies for relating back to native record sets (using a "WHERE ... IN (...)" clause for smaller sets, or using an "INNER JOIN (SELECT ...)" strategy for larger sets). As before, eager fetching avoids the 1+N pitfall, generating only one additional query per relationship (not one per record in the native result set).

Additionally, it is now possible to chain eager fetches. That is, eager-fetched records can themselves eager-fetch their own related records, all with a single call to the Model fetch*() method.

XML-Struct Columns

Solar models support automatic application of serialize() and unserialize() to columns in the $_serialize_cols model property. We now add to this the ability to serialize and unserialize basic XML-formatted data as well, through the use of the new Solar_Struct_Xml class. (N.b.: XML structs do not support attributes.)

Among other things, this means that you can store simplified XML data in a column, and database engines capable of searching it, can search it. You can manipulate that data as XML data in PHP as well via the XML-struct mechanisms.

Non-Model Changes

Arch-Class

The Solar arch-class has fewer static methods in it; collections of related methods have been grouped into their own classes (e.g., [Solar_Config][]).

Construction

The Solar_Base class, from which all other Solar classes extend, now has a more pluggable construction and configuration process. Hooks include:

  • _preConfig() to set up the object before configuration
  • _postConfig() to modify the object after configuration
  • _postConstruct() to complete object construction

This means that you never need to override a Solar constructor; instead, place your construction logic in the applicable hook method.

Page Controllers

The Solar_Controller_Page class now comes with a default layout and views, along with added error handling methods, making it more useful as a base page controller class in its own right. (Previously, one had to extend Solar_App_Base, or create a base app of one's own, to get these basic defaults.)

One thing has been removed: recognition of page-level view helpers. In theory, these seemed like they might be useful. However, in practice, they were rarely if ever needed. Vendor-level helpers are now the first place the views will look.

Lazy Sessions

The Solar_Session class now supports "lazy" sessions. Previously, it would start a sesssion automatically at instantiation time. Now, it starts a session only when ...

  1. A PHP session cookie already exists, or
  2. You call one of the set*() methods to store a value

This means that the session object can be available at any time, but won't invoke any session-based overhead until it is actually needed.

Make-Vendor and Model-Based Apps

The make-vendor command now generates a special page controller called {Vendor}_Controller_Model, which houses all the code for a minimal BREAD-S (browse, read, edit, add, delete, and search) application based on a model.

Previously, make-app would generate the BREAD code fresh in each new class, but when you build mutiple model-based apps, you would end up with a lot of code duplication. The new approach removes that duplication entirely. This means that make-app --model-name will now create app classes that extend from {Vendor}_Controller_Model.

Compound Selects

Solar_Sql_Adapter and Solar_Sql_Select now support UNION and UNION ALL query construction, with the related LIMIT and ORDER components of those kinds of queries.

Forms

The Solar_View_Helper_Form view helper for forms now supports different kinds of decoration: as definition list, as a table, or as "plain" (no surrounding markup). The helper itself has been significantly refactored so that the internal logic is easier to follow, and support logic has been extracted into separate classes when possible.

Much More

There is a lot more to be had. Take a look at the Getting Started documentation, then spend some time with these blog entries from Solar users:


Forty Percent!

Big news (for me anyway): my employer, OmniTI, is allowing me to spend a minimum of 40% of my paid work time on the Solar Framework for PHP 5 (plus additional time as duty allows). The project remains open-source under New BSD license.

The agreement has been in place for several weeks now, and has allowed me to put a lot more effort into the project lately (as a review the SVN logs will reveal) while keeping a paycheck. At the same time, OmniTI gets to show its support for one of the many the open-source communities it has been able to build its business on. Thanks, Theo and Ciprian, for this generous allowance. I appreciate it, and so does everyone who uses Solar; I think it's a big win-win all around.


US Life Expectancy: Best In World?

Apparently "yes", when you control for car crashes and homicides.

One big reason our life expectancy lags is that Americans have an unusual tendency to perish in homicides or accidents. We are 12 times more likely than the Japanese to be murdered and nearly twice as likely to be killed in auto wrecks.

In their 2006 book, The Business of Health, economists Robert L. Ohsfeldt and John E. Schneider set out to determine where the U.S. would rank in life span among developed nations if homicides and accidents are factored out. Their answer? First place.

via The Agitator » Blog Archive » Life Expectancy.

Not sure what this says about US rates of homicide and auto fatalities, but I'm pretty sure it says that the "Americans spend more on health care but don't live as long" trope is misleading at best.



Let insurance companies compete across U.S.

Right now, the U.S. does not have a national market for health insurance. It has 50 separate state markets. Erecting walls around each state means less competition and higher prices for consumers. There's not even one market for the Chicago area. If you live in South Holland or Calumet City, your insurance options could be completely different from your Indiana neighbors in Hammond or Merrillville. What sense does that make?

The easiest way to see how insurance competition benefits consumers is to look at auto insurance. That's a huge, nationwide market and companies compete intensively for a share of it. Some stress their low prices, others customer service, whatever gives them an edge in the marketplace. Geico and Progressive have been especially aggressive in touting cost savings. State Farm and Allstate certainly compete on price, but they stress service after an accident. That's why Allstate says "you're in good hands," and State Farm says it will be there "like a good neighbor." Other companies, like SafeAuto, focus on drivers who want only minimum coverage to meet state license requirements. In short, auto insurance companies compete vigorously to provide what different consumers want, and they tell them so in national advertisements. Life insurance companies do the same thing. There are even companies that specialize in comparing policies for customers. Competition drives down excess profits and means better, cheaper options for consumers.

Ever see an ad touting health insurance? They are rare because the markets are small and companies don't need to compete aggressively on price or service. Introducing such competition would be good for consumers, wouldn't require another Washington bureaucracy and could be done quickly.

via Let insurance companies compete across U.S. -- chicagotribune.com. (All emphasis mine.)



Finally, Some Sensible Health Care Reform Ideas

John Mackey, CEO of Whole Foods, posts The Whole Foods Alternative to ObamaCare at the WSJ.

The 8 things he lists are:

  1. Remove the legal obstacles that slow the creation of high-deductible health insurance plans and health savings accounts (HSAs).
  2. Equalize the tax laws so that employer-provided health insurance and individually owned health insurance have the same tax benefits.
  3. Repeal all state laws which prevent insurance companies from competing across state lines.
  4. Repeal government mandates regarding what insurance companies must cover.
  5. Enact tort reform to end the ruinous lawsuits that force doctors to pay insurance costs of hundreds of thousands of dollars per year.
  6. Make costs transparent so that consumers understand what health-care treatments cost.
  7. Enact Medicare reform.
  8. Finally, revise tax forms to make it easier for individuals to make a voluntary, tax-deductible donation to help the millions of people who have no insurance and aren't covered by Medicare, Medicaid or the State Children's Health Insurance Program.

Go read the whole thing; below, I have some notes of my own.

Point 1 (HSAs) is near and dear to me; I have an HSA and it's great. I get to keep all the money I don't spend; it's mine all mine. That makes me very cost-conscious, and I could be even more cost-conscious if point 6 (cost transparency) was available.

Points 2 (federal tax law), 3 (state law), and 4 (mandated coverage) should be educational to anyone who thinks we already have a free market in health care. We don't. These point out only a few of the kinds of federal and state regulation that reduce the effectiveness of markets.

Not sure how I feel about point 5 (tort reform). I'm definitely in favor of the reform that says "loser pays" but I'm betting that's not what most of the tort reform crowd has in mind.

Point 7 (Medicare reform) is a little vague.

Point 8 (donations to those without insurance) makes for actual *charity*, with all the moral and emotional benefits that confers upon the charitable giver, and not merely confiscation by the government.


46 Million? No, more like 12 million (or less)

Speaking of Obama's scare tactics, that 46 million is a very dubious statistic, the kind Mark Twain had in mind when he talked about lies and damned lies. Here's a chart from a GOP Senator (based on U.S. Census data) that explains who those 46 million actually are.

...

So what we actually have is about 12 million American citizens of income less than $75K who have no access to insurance or government programs. That's about 4% of the population. Many of those are young, healthy people who don't particularly need insurance, and those at incomes of $40-$50K or above can probably afford to borrow and repay medical bills over time; half seems a reasonable estimate of the two combined. So we have 2% of the country that really has a need for this reform.

via Classical Values :: Who's Afraid Of The Big Bad Health Care Crisis?.



What Is Poverty?

When every benefit is received as a right, there is no place for good manners, let alone gratitude.

...

In the welfare state, mere survival is not the achievement that it is, say, in the cities of Africa, and therefore it cannot confer the self-respect that is the precondition of self-improvement.

...

...a system of welfare that makes no moral judgments in allocating economic rewards promotes antisocial egotism.

via Theodore Dalrymple:
What is Poverty?
.